From 7ba419e5d54582404866eda39a9fff7bb3eaa186 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Wed, 20 Apr 2022 01:03:37 +0800 Subject: [PATCH] fix: allow signing a populated transaction (#24475) --- web3.js/src/transaction.ts | 11 +++++------ web3.js/test/transaction.test.ts | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/web3.js/src/transaction.ts b/web3.js/src/transaction.ts index 32dbbe613..aace388b5 100644 --- a/web3.js/src/transaction.ts +++ b/web3.js/src/transaction.ts @@ -167,7 +167,7 @@ export interface TransactionJSON { nonceInstruction: TransactionInstructionJSON; } | null; instructions: TransactionInstructionJSON[]; - signatures: {publicKey: string; signature: number[] | null}[]; + signers: string[]; } /** @@ -242,10 +242,9 @@ export class Transaction { } : null, instructions: this.instructions.map(instruction => instruction.toJSON()), - signatures: this.signatures.map(({publicKey, signature}) => ({ - publicKey: publicKey.toJSON(), - signature: signature ? [...signature] : null, - })), + signers: this.signatures.map(({publicKey}) => { + return publicKey.toJSON(); + }), }; } @@ -280,7 +279,7 @@ export class Transaction { if (this._message) { if (JSON.stringify(this.toJSON()) !== JSON.stringify(this._json)) { throw new Error( - 'Transaction mutated after being populated from Message', + 'Transaction message mutated after being populated from Message', ); } return this._message; diff --git a/web3.js/test/transaction.test.ts b/web3.js/test/transaction.test.ts index 144932371..fabe4b4c6 100644 --- a/web3.js/test/transaction.test.ts +++ b/web3.js/test/transaction.test.ts @@ -134,7 +134,7 @@ describe('Transaction', () => { const fee = await transaction.getEstimatedFee(connection); expect(fee).to.eq(5000); - }); + }).timeout(10 * 1000); it('partialSign', () => { const account1 = Keypair.generate(); @@ -412,7 +412,7 @@ describe('Transaction', () => { transaction.feePayer = new PublicKey(6); expect(() => transaction.compileMessage()).to.throw( - 'Transaction mutated after being populated from Message', + 'Transaction message mutated after being populated from Message', ); }); @@ -612,8 +612,8 @@ describe('Transaction', () => { programId: Keypair.generate().publicKey, }), ); - t0.partialSign(signer); - const t1 = Transaction.from(t0.serialize()); + const t1 = Transaction.from(t0.serialize({requireAllSignatures: false})); + t1.partialSign(signer); t1.serialize(); }); });