Skip to content

Commit 1156a80

Browse files
committed
added unit test for tron helper methods
1 parent 271afda commit 1156a80

File tree

1 file changed

+180
-0
lines changed

1 file changed

+180
-0
lines changed

test/wallet.tron.test.ts

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
import {
2+
createWallet,
3+
generateMnemonic,
4+
generateWalletFromMnemonic,
5+
getAddressFromPrivateKey,
6+
getBalance,
7+
transfer,
8+
getTransaction,
9+
getTokenInfo,
10+
smartContractCall,
11+
} from '../src';
12+
13+
describe('MultichainCryptoWallet Tron tests', () => {
14+
it('generateMnemonic', () => {
15+
const mnemonic = generateMnemonic();
16+
17+
expect(mnemonic).toBeDefined();
18+
});
19+
20+
it('createWallet', () => {
21+
const wallet = createWallet({
22+
network: 'tron',
23+
derivationPath: "m/44'/195'/0'/0/0",
24+
});
25+
expect(wallet).toBeDefined();
26+
});
27+
28+
it('generateWalletFromMnemonic', () => {
29+
const wallet = generateWalletFromMnemonic({
30+
mnemonic:
31+
'crop traffic saddle addict foster split make luxury scissors daughter bike exit',
32+
network: 'tron',
33+
});
34+
expect(wallet).toBeDefined();
35+
});
36+
37+
it('getAddressFromPrivateKey', () => {
38+
const address = getAddressFromPrivateKey({
39+
privateKey:
40+
'fa01dc6efd5fd64e4897aadf255ae715cf34138c7ada5f6a7efb0bdd0bd9c8c4',
41+
network: 'tron',
42+
});
43+
expect(address).toBeDefined();
44+
});
45+
46+
it('getBalance TRX balance', async () => {
47+
const balance = await getBalance({
48+
rpcUrl: 'https://nile.trongrid.io',
49+
address: 'TDdHvW9nU1JaX1P7roYtDvjErTTR17GPJJ',
50+
network: 'tron',
51+
});
52+
expect(balance).toBeDefined();
53+
expect(typeof balance.balance).toBe('string');
54+
});
55+
56+
it('getBalance TRC20 token balance', async () => {
57+
const balance = await getBalance({
58+
rpcUrl: 'https://nile.trongrid.io',
59+
address: 'TEVuGfgLkQCVXs7EtjMiQp3ZSSUkEbNnVS',
60+
network: 'tron',
61+
tokenAddress: 'TXLAQ63Xg1NAzckPwKHvzw7CSEmLMEqcdj',
62+
});
63+
expect(balance).toBeDefined();
64+
expect(typeof balance.balance).toBe('string');
65+
});
66+
67+
it('transfer TRX', async () => {
68+
const tx = await transfer({
69+
rpcUrl: 'https://nile.trongrid.io',
70+
recipientAddress: 'TEVuGfgLkQCVXs7EtjMiQp3ZSSUkEbNnVS',
71+
amount: 0.0001,
72+
network: 'tron',
73+
privateKey:
74+
'fa01dc6efd5fd64e4897aadf255ae715cf34138c7ada5f6a7efb0bdd0bd9c8c4',
75+
});
76+
77+
expect(tx).toBeDefined();
78+
expect(tx.txid).toBeDefined();
79+
});
80+
81+
it('transfer TRC20 token', async () => {
82+
const tx = await transfer({
83+
rpcUrl: 'https://nile.trongrid.io',
84+
recipientAddress: 'TEVuGfgLkQCVXs7EtjMiQp3ZSSUkEbNnVS',
85+
privateKey:
86+
'fa01dc6efd5fd64e4897aadf255ae715cf34138c7ada5f6a7efb0bdd0bd9c8c4',
87+
amount: 0.1,
88+
network: 'tron',
89+
tokenAddress: 'TXLAQ63Xg1NAzckPwKHvzw7CSEmLMEqcdj',
90+
});
91+
92+
expect(tx).toBeDefined();
93+
expect(tx.txid).toBeDefined();
94+
});
95+
96+
it('getTransaction by hash', async () => {
97+
const tx = await getTransaction({
98+
hash: '34f27486cbe693d5182c4b5e18c1779d918668f86f396ed62a279d8b519b81cc',
99+
network: 'tron',
100+
rpcUrl: 'https://nile.trongrid.io',
101+
});
102+
103+
expect(tx).toBeDefined();
104+
});
105+
106+
it('getTokenInfo TRC20 token', async () => {
107+
const data = await getTokenInfo({
108+
address: 'TXLAQ63Xg1NAzckPwKHvzw7CSEmLMEqcdj',
109+
network: 'tron',
110+
rpcUrl: 'https://nile.trongrid.io',
111+
});
112+
113+
expect(typeof data).toBe('object');
114+
expect(typeof (data && data.name)).toBe('string');
115+
expect(typeof (data && data.symbol)).toBe('string');
116+
expect(typeof (data && data.address)).toBe('string');
117+
expect(typeof (data && data.decimals)).toBe('number');
118+
expect(typeof (data && data.totalSupply)).toBe('string');
119+
});
120+
121+
it('smartContractCall write TRC20 token transfer', async () => {
122+
const { data } = await smartContractCall({
123+
network: 'tron',
124+
rpcUrl: 'https://nile.trongrid.io',
125+
contractAddress: 'TXLAQ63Xg1NAzckPwKHvzw7CSEmLMEqcdj',
126+
method: 'transfer(address,uint256)',
127+
methodType: 'write',
128+
contractAbi: [
129+
{
130+
constant: false,
131+
inputs: [
132+
{ name: '_to', type: 'address' },
133+
{ name: '_value', type: 'uint256' },
134+
],
135+
name: 'transfer',
136+
outputs: [{ name: '', type: 'bool' }],
137+
payable: false,
138+
stateMutability: 'nonpayable',
139+
type: 'function',
140+
},
141+
],
142+
params: [
143+
{ type: 'address', value: 'TEVuGfgLkQCVXs7EtjMiQp3ZSSUkEbNnVS' },
144+
{ type: 'uint256', value: 1000000 },
145+
],
146+
privateKey:
147+
'fa01dc6efd5fd64e4897aadf255ae715cf34138c7ada5f6a7efb0bdd0bd9c8c4',
148+
});
149+
150+
expect(data).toBeDefined();
151+
expect(data.txid).toBeDefined();
152+
});
153+
154+
it('smartContractCall read TRC20 token balance', async () => {
155+
const { data } = await smartContractCall({
156+
network: 'tron',
157+
rpcUrl: 'https://nile.trongrid.io',
158+
contractAddress: 'TXLAQ63Xg1NAzckPwKHvzw7CSEmLMEqcdj',
159+
method: 'balanceOf',
160+
methodType: 'read',
161+
contractAbi: [
162+
{
163+
constant: true,
164+
inputs: [{ name: '_owner', type: 'address' }],
165+
name: 'balanceOf',
166+
outputs: [{ name: 'balance', type: 'uint256' }],
167+
payable: false,
168+
stateMutability: 'view',
169+
type: 'function',
170+
},
171+
],
172+
params: [
173+
{ type: 'address', value: 'TEVuGfgLkQCVXs7EtjMiQp3ZSSUkEbNnVS' },
174+
],
175+
});
176+
177+
expect(data).toBeDefined();
178+
expect(typeof data).toBe('string');
179+
});
180+
});

0 commit comments

Comments
 (0)