2018-11-28 10:06:17 -08:00
|
|
|
// @flow
|
|
|
|
import {Account} from '../src/account';
|
2019-01-31 02:16:07 -07:00
|
|
|
import {PublicKey} from '../src/publickey';
|
2018-11-28 10:06:17 -08:00
|
|
|
import {Transaction} from '../src/transaction';
|
|
|
|
import {SystemProgram} from '../src/system-program';
|
|
|
|
|
|
|
|
test('signPartial', () => {
|
|
|
|
const account1 = new Account();
|
|
|
|
const account2 = new Account();
|
2019-03-04 08:06:33 -08:00
|
|
|
const recentBlockhash = account1.publicKey.toBase58(); // Fake recentBlockhash
|
2018-11-28 10:06:17 -08:00
|
|
|
const move = SystemProgram.move(account1.publicKey, account2.publicKey, 123);
|
|
|
|
|
2019-03-04 08:06:33 -08:00
|
|
|
const transaction = new Transaction({recentBlockhash}).add(move);
|
2018-11-28 10:06:17 -08:00
|
|
|
transaction.sign(account1, account2);
|
|
|
|
|
2019-03-04 08:06:33 -08:00
|
|
|
const partialTransaction = new Transaction({recentBlockhash}).add(move);
|
2018-11-28 10:06:17 -08:00
|
|
|
partialTransaction.signPartial(account1, account2.publicKey);
|
|
|
|
expect(partialTransaction.signatures[1].signature).toBeNull();
|
|
|
|
partialTransaction.addSigner(account2);
|
|
|
|
|
|
|
|
expect(partialTransaction).toEqual(transaction);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('transfer signatures', () => {
|
|
|
|
const account1 = new Account();
|
|
|
|
const account2 = new Account();
|
2019-03-04 08:06:33 -08:00
|
|
|
const recentBlockhash = account1.publicKey.toBase58(); // Fake recentBlockhash
|
2018-11-28 10:06:17 -08:00
|
|
|
const move1 = SystemProgram.move(account1.publicKey, account2.publicKey, 123);
|
|
|
|
const move2 = SystemProgram.move(account2.publicKey, account1.publicKey, 123);
|
|
|
|
|
2019-03-04 08:06:33 -08:00
|
|
|
const orgTransaction = new Transaction({recentBlockhash}).add(move1, move2);
|
2018-11-28 10:06:17 -08:00
|
|
|
orgTransaction.sign(account1, account2);
|
|
|
|
|
|
|
|
const newTransaction = new Transaction({
|
2019-03-04 08:06:33 -08:00
|
|
|
recentBlockhash: orgTransaction.recentBlockhash,
|
2018-11-28 10:06:17 -08:00
|
|
|
fee: orgTransaction.fee,
|
|
|
|
signatures: orgTransaction.signatures,
|
|
|
|
}).add(move1, move2);
|
|
|
|
|
|
|
|
expect(newTransaction).toEqual(orgTransaction);
|
|
|
|
});
|
2019-01-31 02:16:07 -07:00
|
|
|
|
|
|
|
test('parse wire format and serialize', () => {
|
2019-03-04 08:06:33 -08:00
|
|
|
const recentBlockhash = 'EETubP5AKHgjPAhzPAFcb8BAY1hMH639CWCFTqi3hq1k'; // Arbitrary known recentBlockhash
|
2019-01-31 02:16:07 -07:00
|
|
|
const sender = new Account(Buffer.alloc(64, 8)); // Arbitrary known account
|
|
|
|
const recipient = new PublicKey(
|
|
|
|
'J3dxNj7nDRRqRRXuEMynDG57DkZK4jYRuv3Garmb1i99',
|
|
|
|
); // Arbitrary known public key
|
|
|
|
const move = SystemProgram.move(sender.publicKey, recipient, 49);
|
2019-03-04 08:06:33 -08:00
|
|
|
const expectedTransaction = new Transaction({recentBlockhash}).add(move);
|
2019-01-31 02:16:07 -07:00
|
|
|
expectedTransaction.sign(sender);
|
|
|
|
|
|
|
|
const wireTransaction = Buffer.from([
|
|
|
|
1,
|
|
|
|
50,
|
|
|
|
238,
|
|
|
|
193,
|
|
|
|
5,
|
|
|
|
227,
|
|
|
|
31,
|
|
|
|
95,
|
|
|
|
69,
|
|
|
|
85,
|
|
|
|
3,
|
|
|
|
132,
|
|
|
|
143,
|
|
|
|
216,
|
|
|
|
77,
|
|
|
|
235,
|
|
|
|
129,
|
|
|
|
3,
|
|
|
|
109,
|
|
|
|
89,
|
|
|
|
222,
|
|
|
|
127,
|
|
|
|
137,
|
|
|
|
228,
|
|
|
|
15,
|
|
|
|
113,
|
|
|
|
207,
|
|
|
|
169,
|
|
|
|
93,
|
|
|
|
167,
|
|
|
|
249,
|
|
|
|
71,
|
|
|
|
33,
|
|
|
|
185,
|
|
|
|
182,
|
|
|
|
83,
|
|
|
|
116,
|
|
|
|
203,
|
|
|
|
102,
|
|
|
|
64,
|
|
|
|
245,
|
|
|
|
68,
|
|
|
|
34,
|
|
|
|
100,
|
|
|
|
193,
|
|
|
|
156,
|
|
|
|
109,
|
|
|
|
35,
|
|
|
|
104,
|
|
|
|
119,
|
|
|
|
101,
|
|
|
|
197,
|
|
|
|
43,
|
|
|
|
141,
|
|
|
|
174,
|
|
|
|
228,
|
|
|
|
154,
|
|
|
|
146,
|
|
|
|
78,
|
|
|
|
216,
|
|
|
|
202,
|
|
|
|
18,
|
|
|
|
177,
|
|
|
|
179,
|
|
|
|
5,
|
|
|
|
2,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
8,
|
|
|
|
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,
|
|
|
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
0,
|
|
|
|
]);
|
|
|
|
const tx = Transaction.from(wireTransaction);
|
|
|
|
|
|
|
|
expect(tx).toEqual(expectedTransaction);
|
|
|
|
expect(wireTransaction).toEqual(expectedTransaction.serialize());
|
|
|
|
});
|