test: add test for external Transaction
signing
This commit is contained in:
parent
8142aa6c1d
commit
403448a91f
@ -439,3 +439,22 @@ test('serialize unsigned transaction', () => {
|
|||||||
expectedTransaction,
|
expectedTransaction,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('get sign data for transaction', () => {
|
||||||
|
const from_keypair = nacl.sign.keyPair.fromSeed(
|
||||||
|
Uint8Array.from(Array(32).fill(1)),
|
||||||
|
);
|
||||||
|
const from = new Account(Buffer.from(from_keypair.secretKey));
|
||||||
|
const to = new PublicKey(2);
|
||||||
|
const recentBlockhash = new PublicKey(3).toBuffer();
|
||||||
|
var tx = SystemProgram.transfer({
|
||||||
|
fromPubkey: from.publicKey,
|
||||||
|
toPubkey: to,
|
||||||
|
lamports: 42,
|
||||||
|
});
|
||||||
|
tx.recentBlockhash = bs58.encode(recentBlockhash);
|
||||||
|
const tx_bytes = tx.signData;
|
||||||
|
const signature = nacl.sign.detached(tx_bytes, from.secretKey);
|
||||||
|
tx.addSignature(from.publicKey, signature);
|
||||||
|
expect(tx.verifySignatures()).toBe(true);
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user