2020-05-26 22:49:11 +02:00
|
|
|
import assert from 'assert'
|
2020-08-22 04:29:19 +02:00
|
|
|
import { ethers } from 'ethers'
|
2020-05-26 22:49:11 +02:00
|
|
|
import { renderHook } from '@testing-library/react-hooks'
|
2020-08-18 21:18:25 +02:00
|
|
|
import { useTokenData } from '../useTokenData'
|
2020-05-26 22:49:11 +02:00
|
|
|
|
|
|
|
const tests = [
|
|
|
|
{
|
|
|
|
data: '0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a970000000000000000000000000000000000000000000000000000000000003a98',
|
|
|
|
tokenData: {
|
|
|
|
'name': 'transfer',
|
2020-08-22 04:29:19 +02:00
|
|
|
'args': [
|
|
|
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
|
|
|
ethers.BigNumber.from(15000),
|
2020-05-26 22:49:11 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: '0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a9700000000000000000000000000000000000000000000000000000000000061a8',
|
|
|
|
tokenData: {
|
|
|
|
'name': 'transfer',
|
2020-08-22 04:29:19 +02:00
|
|
|
'args': [
|
|
|
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
|
|
|
ethers.BigNumber.from(25000),
|
2020-05-26 22:49:11 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: '0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a970000000000000000000000000000000000000000000000000000000000002710',
|
|
|
|
tokenData: {
|
|
|
|
'name': 'transfer',
|
2020-08-22 04:29:19 +02:00
|
|
|
'args': [
|
|
|
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
|
|
|
ethers.BigNumber.from(10000),
|
2020-05-26 22:49:11 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: undefined,
|
|
|
|
tokenData: null,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
describe('useTokenData', function () {
|
|
|
|
tests.forEach((test) => {
|
2020-08-14 13:47:43 +02:00
|
|
|
const testTitle = test.tokenData === null
|
|
|
|
? `should return null when no data provided`
|
2020-08-22 04:29:19 +02:00
|
|
|
: `should return properly decoded data with _value ${test.tokenData.args[1].value}`
|
2020-05-26 22:49:11 +02:00
|
|
|
it(testTitle, function () {
|
|
|
|
const { result } = renderHook(() => useTokenData(test.data))
|
2020-08-22 04:29:19 +02:00
|
|
|
if (test.tokenData) {
|
|
|
|
assert.equal(result.current.name, test.tokenData.name)
|
|
|
|
assert.equal(result.current.args[0].toLowerCase(), test.tokenData.args[0])
|
|
|
|
assert.ok(test.tokenData.args[1].eq(result.current.args[1]))
|
|
|
|
} else {
|
|
|
|
assert.equal(result.current, test.tokenData)
|
|
|
|
}
|
2020-05-26 22:49:11 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|