-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.spec.ts
59 lines (45 loc) · 1.89 KB
/
tests.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { LocalKoinos, Token, Signer } from '../lib';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import * as abi from './calculator-abi.json';
// @ts-ignore koilib_types is needed when using koilib
abi.koilib_types = abi.types
jest.setTimeout(600000);
const localKoinos = new LocalKoinos();
beforeAll(async () => {
// start local-koinos node
await localKoinos.startNode();
await localKoinos.startBlockProduction();
await localKoinos.deployKoinContract();
await localKoinos.mintKoinDefaultAccounts();
});
afterAll(async () => {
// stop local-koinos node
await localKoinos.stopNode();
});
test("test1", async () => {
const [genesis, koin, acct1] = localKoinos.getAccounts();
// @ts-ignore abi provided here is compatible with Koilib
const contract = await localKoinos.deployContract(acct1.wif, './tests/calculator-contract.wasm', abi);
const { result } = await contract.functions.add({ x: '4', y: '5' });
expect(result!.value).toBe('9');
const signer = Signer.fromWif('L59UtJcTdNBnrH2QSBA5beSUhRufRu3g6tScDTite6Msuj7U93tM');
signer.provider = localKoinos.getProvider();
let tkn = new Token(localKoinos.koin.address(), signer);
try {
await tkn.mint(signer.address, 40);
} catch (error) {
// @ts-ignore
expect(error.message).toContain('can only mint token with contract authority');
}
try {
const signer2 = Signer.fromWif('5KL5GNq42Syr52dUUi4UhQ5cANwNr9xgxKivF9YjtGdM7BBjuks');
signer2.provider = localKoinos.getProvider();
tkn = new Token(localKoinos.koin.address(), signer2);
const { transaction, receipt } = await tkn.transfer(signer2.address, signer.address, 40000000000000000);
await transaction!.wait();
} catch (error) {
// @ts-ignore
expect(error.message).toContain("account 'from' has insufficient balance");
}
});