Skip to content

Commit

Permalink
fix trc20 large amount error (#142)
Browse files Browse the repository at this point in the history
Co-authored-by: Li Tian <tli2@cobo.com>
  • Loading branch information
soralit and Li Tian authored Oct 2, 2020
1 parent 8d3b7ba commit a9f69d1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crypto-coin-kit",
"version": "0.2.35",
"version": "0.2.37",
"description": "crypto coin kit for common coins",
"main": "./dist/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/TRON/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface TxData {
from: string;
to: string;
memo?: string;
value: number;
value: string;
latestBlock: LatestBlock;
override?: Override;
fee: number;
Expand Down Expand Up @@ -268,7 +268,7 @@ export class TRON implements Coin {
return this.refWithLatestBlock(tx, txData.latestBlock, true);
};

private composeTRC20Data = (to: string, value = 0) => {
private composeTRC20Data = (to: string, value = '0') => {
const functionSelector = 'transfer(address,uint256)';
const types = ['address', 'uint256'];
const toAddress = bs58check
Expand Down
31 changes: 28 additions & 3 deletions src/__tests__/coins/TRON.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const txData: TxData = {
token: 'TRX',
from: 'TTiYGxb7YNfUQJAnLFMd1pvmoywM7PxiG2',
to: 'TXhtYr8nmgiSp3dY3cSfiKBjed3zN8teHS',
value: 2000000,
value: '2000000',
fee: 100000,
latestBlock: {
hash: '36f6939bb2fa89e8ec27b63954f5913d143d2fa18f9bd93ebcb57055ecb2057c',
Expand All @@ -22,7 +22,7 @@ const txData: TxData = {
const txDataTRC10: TxData = {
to: 'TKCsXtfKfH2d6aEaQCctybDC9uaA3MSj2h',
from: 'TXhtYr8nmgiSp3dY3cSfiKBjed3zN8teHS',
value: 1,
value: '1',
memo: '',
fee: 100000,
latestBlock: {
Expand All @@ -42,7 +42,20 @@ const txDataTRC20: TxData = {
contractAddress: 'TBAo7PNyKo94YWUq1Cs2LBFxkhTphnAE4T',
to: 'TQAg2T2vJcHAX9sbKTEoaoWzt512yUjiFD',
from: 'TUAhxw3MgMyR9rhyrMDnVJbo3bky1GSUrH',
value: 1000000,
value: '1000000',
fee: 1,
latestBlock: {
hash: '315f1ee0e082a1dae1b9de559665c6714f3b8667f69cd5e44466ba6e34d37aef',
number: 1936,
timestamp: 1527682440000,
},
};

const txDataTRC20_1: TxData = {
contractAddress: 'TBAo7PNyKo94YWUq1Cs2LBFxkhTphnAE4T',
to: 'TQAg2T2vJcHAX9sbKTEoaoWzt512yUjiFD',
from: 'TUAhxw3MgMyR9rhyrMDnVJbo3bky1GSUrH',
value: '3000000000000000000000',
fee: 1,
latestBlock: {
hash: '315f1ee0e082a1dae1b9de559665c6714f3b8667f69cd5e44466ba6e34d37aef',
Expand Down Expand Up @@ -115,6 +128,18 @@ describe('coin.TRON', () => {
);
});

it('should generate signed large amount TRC20 token', async () => {
const tx = await tron.generateTransaction(
txDataTRC20_1,
signWithPrivateKey(
'986e593a779463e5d15fba95939f22d48736ccac90d4d451942cdc1047757f06',
),
);
expect(tx.txHex).toBe(
'0ad4010a0207902208e1b9de559665c6714080c49789bb2c5aae01081f12a9010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412740a1541c79f045e4d48ad8dae00e6a6714dae1e000adfcd1215410d292c98a5eca06c2085fff993996423cf66c93b2244a9059cbb0000000000000000000000009bbce520d984c3b95ad10cb4e32a9294e6338da30000000000000000000000000000000000000000000000a2a15d09519be0000070c0b6e087bb2c90018094ebdc03124186888c5ab8d0f8d96090703f85069caea61ac13cf71c5ff7d04727a1ab0fb2ba73924a5902b58b82c9195cc1e1ce7697dbc15df74d7e947d49f98ff831c52e9d00',
);
});

it('should sign message', async () => {
expect(await tron.signMessage('hello', signWithPrivateKey(privKey))).toBe(
'7f99c6d07404346ec0094a5790fe631c8145a3a6203708ef2d1b984c35eb38b2cc74a50273dc1007728fb49e1d2923f1684594e94abbd4ed1c77afdb45114b5600',
Expand Down

0 comments on commit a9f69d1

Please sign in to comment.