-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for TokenBalance and ScriptBalances as they are reused now
- Loading branch information
ivan
committed
May 3, 2021
1 parent
aef6d35
commit 276ad5c
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
packages/jellyfish-transaction/__tests__/script/defi/dftx_balance/ScriptBalances.test.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,35 @@ | ||
import BigNumber from 'bignumber.js' | ||
import { SmartBuffer } from 'smart-buffer' | ||
import { CScriptBalances, ScriptBalances } from '../../../../src/script/defi/dftx_balance' | ||
import { OP_CODES } from '../../../../src/script' | ||
|
||
const data = '17a914d6e3de1c51f22e580944bb6a1647f1d22f0159c78701000000007030e65502000000' | ||
const scriptBalances: ScriptBalances = { | ||
script: { | ||
stack: [ | ||
OP_CODES.OP_HASH160, | ||
OP_CODES.OP_PUSHDATA_HEX_LE('d6e3de1c51f22e580944bb6a1647f1d22f0159c7'), | ||
OP_CODES.OP_EQUAL | ||
] | ||
}, | ||
balances: [ | ||
{ | ||
amount: new BigNumber('100.31083632'), token: 0 | ||
} | ||
] | ||
} | ||
|
||
describe('Composable', () => { | ||
it('should compose from buffer to composable', () => { | ||
const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex')) | ||
const composable = new CScriptBalances(buffer) | ||
expect(composable.toObject()).toEqual(scriptBalances) | ||
}) | ||
|
||
it('should compose from composable to buffer', () => { | ||
const composable = new CScriptBalances(scriptBalances) | ||
const buffer = new SmartBuffer() | ||
composable.toBuffer(buffer) | ||
expect(buffer.toBuffer().toString('hex')).toEqual(data) | ||
}) | ||
}) |
24 changes: 24 additions & 0 deletions
24
packages/jellyfish-transaction/__tests__/script/defi/dftx_balance/TokenBalance.test.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,24 @@ | ||
import BigNumber from 'bignumber.js' | ||
import { SmartBuffer } from 'smart-buffer' | ||
import { CTokenBalance, TokenBalance } from '../../../../src/script/defi/dftx_balance' | ||
|
||
const data = '000000003da5a50300000000' | ||
const tokenBalance: TokenBalance = { | ||
token: 0, | ||
amount: new BigNumber('0.61187389') | ||
} | ||
|
||
describe('Composable', () => { | ||
it('should compose from buffer to composable', () => { | ||
const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex')) | ||
const composable = new CTokenBalance(buffer) | ||
expect(composable.toObject()).toEqual(tokenBalance) | ||
}) | ||
|
||
it('should compose from composable to buffer', () => { | ||
const composable = new CTokenBalance(tokenBalance) | ||
const buffer = new SmartBuffer() | ||
composable.toBuffer(buffer) | ||
expect(buffer.toBuffer().toString('hex')).toEqual(data) | ||
}) | ||
}) |