Skip to content

Commit 69e7b4e

Browse files
committed
test: mint-token tests
1 parent d27fed8 commit 69e7b4e

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
import { TestUtils } from './utils/test-utils-integration';
2+
import { WalletHelper } from './utils/wallet-helper';
3+
4+
describe('mint token', () => {
5+
let wallet1;
6+
const tokenA = {
7+
name: 'Token A',
8+
symbol: 'TKA',
9+
uid: null
10+
};
11+
12+
beforeAll(async () => {
13+
wallet1 = new WalletHelper('mint-token-1');
14+
15+
// Starting the wallets
16+
await WalletHelper.startMultipleWalletsForTest([wallet1]);
17+
18+
// Creating a token for the tests
19+
await wallet1.injectFunds(10, 0, { doNotWait: true });
20+
const tkAtx = await wallet1.createToken({
21+
name: tokenA.name,
22+
symbol: tokenA.symbol,
23+
amount: 500,
24+
address: await wallet1.getAddressAt(0),
25+
change_address: await wallet1.getAddressAt(0)
26+
});
27+
tokenA.uid = tkAtx.hash;
28+
});
29+
30+
afterAll(async () => {
31+
await wallet1.stop();
32+
});
33+
34+
// Testing failures first, that do not cause side-effects on the blockchain
35+
36+
it('should not mint an invalid token', async done => {
37+
const response = await TestUtils.request
38+
.post('/wallet/mint-tokens')
39+
.send({
40+
token: 'invalidToken',
41+
address: await wallet1.getAddressAt(1),
42+
amount: 100
43+
})
44+
.set({ 'x-wallet-id': wallet1.walletId });
45+
46+
expect(response.status)
47+
.toBe(200);
48+
expect(response.body.success)
49+
.toBe(false);
50+
51+
// Even though the result is correct, the error thrown is not related. Should be fixed later.
52+
// expect(response.body.message).toContain('invalid');
53+
done();
54+
});
55+
56+
it('should not mint with an invalid address', async done => {
57+
const response = await TestUtils.request
58+
.post('/wallet/mint-tokens')
59+
.send({
60+
token: tokenA.uid,
61+
address: 'invalidAddress',
62+
amount: 100
63+
})
64+
.set({ 'x-wallet-id': wallet1.walletId });
65+
66+
expect(response.status)
67+
.toBe(200);
68+
expect(response.body.success)
69+
.toBe(false);
70+
expect(response.body.error)
71+
.toContain('base58');
72+
done();
73+
});
74+
75+
it('should not mint with an invalid change address', async done => {
76+
const response = await TestUtils.request
77+
.post('/wallet/mint-tokens')
78+
.send({
79+
token: tokenA.uid,
80+
address: await wallet1.getAddressAt(1),
81+
change_address: 'invalidAddress',
82+
amount: 100
83+
})
84+
.set({ 'x-wallet-id': wallet1.walletId });
85+
86+
expect(response.status)
87+
.toBe(200);
88+
expect(response.body.success)
89+
.toBe(false);
90+
expect(response.body.error)
91+
.toContain('invalid');
92+
done();
93+
});
94+
95+
it('should not mint with an invalid amount', async done => {
96+
const response = await TestUtils.request
97+
.post('/wallet/mint-tokens')
98+
.send({
99+
token: tokenA.uid,
100+
address: await wallet1.getAddressAt(1),
101+
amount: 'invalidVamount'
102+
})
103+
.set({ 'x-wallet-id': wallet1.walletId });
104+
105+
expect(response.status)
106+
.toBe(400);
107+
expect(response.body.success)
108+
.toBe(false);
109+
expect(response.text)
110+
.toContain('invalid');
111+
done();
112+
});
113+
114+
// Insufficient funds
115+
116+
it('should not mint with insuficcient funds', async done => {
117+
const response = await TestUtils.request
118+
.post('/wallet/mint-tokens')
119+
.send({
120+
token: tokenA.uid,
121+
address: await wallet1.getAddressAt(1),
122+
amount: 1000
123+
})
124+
.set({ 'x-wallet-id': wallet1.walletId });
125+
126+
expect(response.status)
127+
.toBe(200);
128+
expect(response.body.success)
129+
.toBe(false);
130+
expect(response.body.error)
131+
.toContain('HTR funds');
132+
done();
133+
});
134+
135+
// Success
136+
137+
it('should mint without a change address', async done => {
138+
const response = await TestUtils.request
139+
.post('/wallet/mint-tokens')
140+
.send({
141+
token: tokenA.uid,
142+
address: await wallet1.getAddressAt(1),
143+
amount: 300
144+
})
145+
.set({ 'x-wallet-id': wallet1.walletId });
146+
147+
expect(response.body.success)
148+
.toBe(true);
149+
done();
150+
});
151+
152+
it('should mint with a change address', async done => {
153+
const response = await TestUtils.request
154+
.post('/wallet/mint-tokens')
155+
.send({
156+
token: tokenA.uid,
157+
address: await wallet1.getAddressAt(1),
158+
change_address: await wallet1.getAddressAt(10),
159+
amount: 100
160+
})
161+
.set({ 'x-wallet-id': wallet1.walletId });
162+
163+
expect(response.body.success)
164+
.toBe(true);
165+
166+
const addr10 = await wallet1.getAddressInfo(10);
167+
expect(addr10.total_amount_received)
168+
.toBe(1);
169+
done();
170+
});
171+
});

0 commit comments

Comments
 (0)