Skip to content

Commit

Permalink
fix: DelegateAction Schema (#1314)
Browse files Browse the repository at this point in the history
The current schema has two fields swapped (actions and nonce), which
makes it impossible to create DelegateActions, since the borsh
serialization ends up mixing the nonce with the action
  • Loading branch information
gagdiez committed Mar 11, 2024
1 parent 5518fe6 commit 42dc7e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/happy-onions-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@near-js/transactions": patch
---

Fixed delegateAction Schema
2 changes: 1 addition & 1 deletion packages/transactions/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ export const SCHEMA = new class BorshSchema {
struct: {
senderId: 'string',
receiverId: 'string',
nonce: 'u64',
actions: { array: { type: this.ClassicActions } },
nonce: 'u64',
maxBlockHeight: 'u64',
publicKey: this.PublicKey,
}
Expand Down
8 changes: 8 additions & 0 deletions packages/transactions/test/serialize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ test('serialize object', async () => {
expect(new_value.q).toEqual([1, 2, 3]);
});

test('deserialize delegate', async () => {
const serialized = [8, 16, 0, 0, 0, 116, 104, 101, 45, 117, 115, 101, 114, 46, 116, 101, 115, 116, 110, 101, 116, 27, 0, 0, 0, 104, 101, 108, 108, 111, 46, 110, 101, 97, 114, 45, 101, 120, 97, 109, 112, 108, 101, 115, 46, 116, 101, 115, 116, 110, 101, 116, 1, 0, 0, 0, 2, 12, 0, 0, 0, 115, 101, 116, 95, 103, 114, 101, 101, 116, 105, 110, 103, 20, 0, 0, 0, 123, 34, 103, 114, 101, 101, 116, 105, 110, 103, 34, 58, 34, 72, 101, 108, 108, 111, 34, 125, 0, 224, 87, 235, 72, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 9, 120, 166, 131, 144, 0, 0, 61, 158, 123, 9, 0, 0, 0, 0, 0, 154, 156, 80, 116, 108, 65, 42, 39, 47, 253, 146, 109, 67, 106, 83, 230, 57, 183, 195, 122, 150, 6, 246, 220, 173, 35, 120, 139, 167, 94, 183, 29, 0, 41, 98, 10, 45, 51, 177, 89, 159, 190, 247, 41, 255, 243, 17, 186, 140, 168, 139, 9, 81, 33, 8, 74, 73, 85, 254, 127, 62, 54, 193, 60, 50, 235, 49, 13, 37, 152, 94, 172, 24, 198, 220, 119, 148, 99, 89, 19, 187, 251, 80, 76, 230, 77, 28, 80, 140, 133, 81, 139, 159, 62, 245, 167, 4];
const { signedDelegate: { delegateAction } } = deserialize(SCHEMA.Action, serialized);
expect(delegateAction.senderId).toEqual('the-user.testnet');
expect(delegateAction.receiverId).toEqual('hello.near-examples.testnet');
expect(String(delegateAction.nonce)).toEqual('158895108000003');
});

test('serialize and sign multi-action tx', async () => {
const keyStore = new InMemoryKeyStore();
const keyPair = KeyPair.fromString('ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw');
Expand Down

0 comments on commit 42dc7e2

Please sign in to comment.