|
| 1 | +// Copyright © 2017-2020 Trust Wallet. |
| 2 | +// |
| 3 | +// This file is part of Trust. The full Trust copyright notice, including |
| 4 | +// terms governing use, modification, and redistribution, is contained in the |
| 5 | +// file LICENSE at the root of the source code distribution tree. |
| 6 | + |
| 7 | +import 'mocha' |
| 8 | +import { expect } from 'chai' |
| 9 | +import { Buffer } from 'buffer' |
| 10 | +import { TW, CoinType } from '../dist' |
| 11 | + |
| 12 | +describe('Wallet Core types tests', () => { |
| 13 | + |
| 14 | + it('test CoinType.ethereum', () => { |
| 15 | + const coin = CoinType.ethereum; |
| 16 | + expect(coin).to.equal(60) |
| 17 | + expect(CoinType.id(coin)).to.equal('ethereum') |
| 18 | + expect(CoinType.name(coin)).to.equal('Ethereum') |
| 19 | + expect(CoinType.symbol(coin)).to.equal('ETH') |
| 20 | + expect(CoinType.decimals(coin)).to.equal(18) |
| 21 | + expect(CoinType.derivationPath(coin)).to.equal(`m/44'/60'/0'/0/0`) |
| 22 | + }) |
| 23 | + |
| 24 | + it('test Ethereum encoding SigningInput', () => { |
| 25 | + const input = TW.Ethereum.Proto.SigningInput.create({ |
| 26 | + toAddress: '0x3535353535353535353535353535353535353535', |
| 27 | + chainId: Buffer.from('01', 'hex'), |
| 28 | + nonce: Buffer.from('09', 'hex'), |
| 29 | + gasPrice: Buffer.from('04a817c800', 'hex'), |
| 30 | + gasLimit: Buffer.from('5208', 'hex'), |
| 31 | + amount: Buffer.from('0de0b6b3a7640000', 'hex'), |
| 32 | + privateKey: Buffer.from('4646464646464646464646464646464646464646464646464646464646464646', 'hex') |
| 33 | + }); |
| 34 | + |
| 35 | + const encoded = TW.Ethereum.Proto.SigningInput.encode(input).finish() |
| 36 | + expect(Buffer.from(encoded).toString('hex')).to.equal("0a01011201091a0504a817c800220252082a2a30783335333533353335333533353335333533353335333533353335333533353335333533353335333532080de0b6b3a764000042204646464646464646464646464646464646464646464646464646464646464646") |
| 37 | + }) |
| 38 | +}) |
0 commit comments