fix: serializing an unsigned tx should throw
This commit is contained in:
committed by
Trent Nelson
parent
57576b07ef
commit
3e3241125f
@ -400,7 +400,7 @@ export class Transaction {
|
|||||||
*/
|
*/
|
||||||
serialize(): Buffer {
|
serialize(): Buffer {
|
||||||
const {signatures} = this;
|
const {signatures} = this;
|
||||||
if (!signatures) {
|
if (!signatures || signatures.length === 0 || !this.verifySignatures()) {
|
||||||
throw new Error('Transaction has not been signed');
|
throw new Error('Transaction has not been signed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,231 +212,31 @@ test('serialize unsigned transaction', () => {
|
|||||||
});
|
});
|
||||||
const expectedTransaction = new Transaction({recentBlockhash}).add(transfer);
|
const expectedTransaction = new Transaction({recentBlockhash}).add(transfer);
|
||||||
|
|
||||||
const wireTransactionArray = [
|
// Empty signature array fails.
|
||||||
1,
|
expect(expectedTransaction.signatures.length).toBe(0);
|
||||||
0,
|
expect(() => {
|
||||||
0,
|
expectedTransaction.serialize();
|
||||||
0,
|
}).toThrow(Error);
|
||||||
0,
|
expect(expectedTransaction.signatures.length).toBe(0);
|
||||||
0,
|
// Signature array populated with null signatures fails.
|
||||||
0,
|
expectedTransaction.serializeMessage();
|
||||||
0,
|
expect(expectedTransaction.signatures.length).toBe(1);
|
||||||
0,
|
expect(() => {
|
||||||
0,
|
expectedTransaction.serialize();
|
||||||
0,
|
}).toThrow(Error);
|
||||||
0,
|
expect(expectedTransaction.signatures.length).toBe(1);
|
||||||
0,
|
// Properly signed transaction succeeds
|
||||||
0,
|
expectedTransaction.sign(sender);
|
||||||
0,
|
expect(expectedTransaction.signatures.length).toBe(1);
|
||||||
0,
|
const expectedSerialization = Buffer.from(
|
||||||
0,
|
'AVuErQHaXv0SG0/PchunfxHKt8wMRfMZzqV0tkC5qO6owYxWU2v871AoWywGoFQr4z+q/7mE8lIufNl/' +
|
||||||
0,
|
'kxj+nQ0BAAEDE5j2LG0aRXxRumpLXz29L2n8qTIWIY3ImX5Ba9F9k8r9Q5/Mtmcn8onFxt47xKj+XdXX' +
|
||||||
0,
|
'd3C8j/FcPu7csUrz/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAxJrndgN4IFTxep3s6kO0' +
|
||||||
0,
|
'ROug7bEsbx0xxuDkqEvwUusBAgIAAQwCAAAAMQAAAAAAAAA=',
|
||||||
0,
|
'base64',
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
3,
|
|
||||||
19,
|
|
||||||
152,
|
|
||||||
246,
|
|
||||||
44,
|
|
||||||
109,
|
|
||||||
26,
|
|
||||||
69,
|
|
||||||
124,
|
|
||||||
81,
|
|
||||||
186,
|
|
||||||
106,
|
|
||||||
75,
|
|
||||||
95,
|
|
||||||
61,
|
|
||||||
189,
|
|
||||||
47,
|
|
||||||
105,
|
|
||||||
252,
|
|
||||||
169,
|
|
||||||
50,
|
|
||||||
22,
|
|
||||||
33,
|
|
||||||
141,
|
|
||||||
200,
|
|
||||||
153,
|
|
||||||
126,
|
|
||||||
65,
|
|
||||||
107,
|
|
||||||
209,
|
|
||||||
125,
|
|
||||||
147,
|
|
||||||
202,
|
|
||||||
253,
|
|
||||||
67,
|
|
||||||
159,
|
|
||||||
204,
|
|
||||||
182,
|
|
||||||
103,
|
|
||||||
39,
|
|
||||||
242,
|
|
||||||
137,
|
|
||||||
197,
|
|
||||||
198,
|
|
||||||
222,
|
|
||||||
59,
|
|
||||||
196,
|
|
||||||
168,
|
|
||||||
254,
|
|
||||||
93,
|
|
||||||
213,
|
|
||||||
215,
|
|
||||||
119,
|
|
||||||
112,
|
|
||||||
188,
|
|
||||||
143,
|
|
||||||
241,
|
|
||||||
92,
|
|
||||||
62,
|
|
||||||
238,
|
|
||||||
220,
|
|
||||||
177,
|
|
||||||
74,
|
|
||||||
243,
|
|
||||||
252,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
196,
|
|
||||||
154,
|
|
||||||
231,
|
|
||||||
118,
|
|
||||||
3,
|
|
||||||
120,
|
|
||||||
32,
|
|
||||||
84,
|
|
||||||
241,
|
|
||||||
122,
|
|
||||||
157,
|
|
||||||
236,
|
|
||||||
234,
|
|
||||||
67,
|
|
||||||
180,
|
|
||||||
68,
|
|
||||||
235,
|
|
||||||
160,
|
|
||||||
237,
|
|
||||||
177,
|
|
||||||
44,
|
|
||||||
111,
|
|
||||||
29,
|
|
||||||
49,
|
|
||||||
198,
|
|
||||||
224,
|
|
||||||
228,
|
|
||||||
168,
|
|
||||||
75,
|
|
||||||
240,
|
|
||||||
82,
|
|
||||||
235,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
12,
|
|
||||||
2,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
49,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
];
|
|
||||||
|
|
||||||
const wireTransaction = Buffer.from(wireTransactionArray);
|
|
||||||
expect(wireTransaction).toEqual(expectedTransaction.serialize());
|
|
||||||
expect(Transaction.from(wireTransaction)).toEqual(expectedTransaction);
|
|
||||||
expect(Transaction.from(wireTransactionArray)).toEqual(expectedTransaction);
|
|
||||||
expect(Transaction.from(Uint8Array.from(wireTransactionArray))).toEqual(
|
|
||||||
expectedTransaction,
|
|
||||||
);
|
);
|
||||||
|
expect(expectedTransaction.serialize()).toStrictEqual(expectedSerialization);
|
||||||
|
expect(expectedTransaction.signatures.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('get sign data for transaction', () => {
|
test('get sign data for transaction', () => {
|
||||||
|
Reference in New Issue
Block a user