-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4284 from BitGo/WIN-1961-update-encoding
chore(sdk-coin-zketh): fix transaction endcoding method for zksync
- Loading branch information
Showing
4 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
modules/sdk-coin-zketh/test/unit/transactionBuilder/send.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { TransactionType } from '@bitgo/sdk-core'; | ||
import should from 'should'; | ||
import { decodeTransferData } from '@bitgo/abstract-eth'; | ||
import * as testData from '../../resources'; | ||
import { getBuilder } from '../../getBuilder'; | ||
import { TransactionBuilder } from '../../../src'; | ||
|
||
describe('ZKeth transaction builder send', () => { | ||
describe('should sign and build', () => { | ||
let txBuilder; | ||
let key; | ||
let contractAddress; | ||
|
||
beforeEach(() => { | ||
contractAddress = '0x8f977e912ef500548a0c3be6ddde9899f1199b81'; | ||
txBuilder = getBuilder('tzketh') as TransactionBuilder; | ||
key = testData.KEYPAIR_PRV.getKeys().prv as string; | ||
txBuilder.fee({ | ||
fee: '1000000000', | ||
gasLimit: '12100000', | ||
}); | ||
txBuilder.counter(2); | ||
txBuilder.type(TransactionType.Send); | ||
txBuilder.contract(contractAddress); | ||
}); | ||
|
||
it('a send funds transaction', async () => { | ||
const recipient = '0x19645032c7f1533395d44a629462e751084d3e4c'; | ||
const amount = '1000000000'; | ||
const expireTime = 1590066728; | ||
const sequenceId = 5; | ||
txBuilder | ||
.transfer() | ||
.amount(amount) | ||
.to(recipient) | ||
.expirationTime(expireTime) | ||
.contractSequenceId(sequenceId) | ||
.key(key); | ||
txBuilder.sign({ key: testData.PRIVATE_KEY_1 }); | ||
const tx = await txBuilder.build(); | ||
|
||
should.equal(tx.toJson().chainId, '0x12c'); | ||
should.equal(tx.toBroadcastFormat(), testData.SEND_TX_BROADCAST_LEGACY); | ||
should.equal(tx.signature.length, 2); | ||
should.equal(tx.inputs.length, 1); | ||
should.equal(tx.inputs[0].address, contractAddress); | ||
should.equal(tx.inputs[0].value, amount); | ||
|
||
should.equal(tx.outputs.length, 1); | ||
should.equal(tx.outputs[0].address, recipient); | ||
should.equal(tx.outputs[0].value, amount); | ||
|
||
const data = tx.toJson().data; | ||
const { | ||
to, | ||
amount: parsedAmount, | ||
expireTime: parsedExpireTime, | ||
sequenceId: parsedSequenceId, | ||
} = decodeTransferData(data); | ||
should.equal(to, recipient); | ||
should.equal(parsedAmount, amount); | ||
should.equal(parsedExpireTime, expireTime); | ||
should.equal(parsedSequenceId, sequenceId); | ||
}); | ||
|
||
it('a send funds with amount 0 transaction', async () => { | ||
txBuilder | ||
.transfer() | ||
.amount('0') | ||
.to('0x19645032c7f1533395d44a629462e751084d3e4c') | ||
.expirationTime(1590066728) | ||
.contractSequenceId(5) | ||
.key(key); | ||
txBuilder.sign({ key: testData.PRIVATE_KEY_1 }); | ||
const tx = await txBuilder.build(); | ||
should.equal(tx.toBroadcastFormat(), testData.SEND_TX_AMOUNT_ZERO_BROADCAST); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters