forked from hyperledger-solang/solang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntime_error.spec.js
48 lines (34 loc) · 1.47 KB
/
runtime_error.spec.js
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
import * as StellarSdk from '@stellar/stellar-sdk';
import { readFileSync } from 'fs';
import { expect } from 'chai';
import path from 'path';
import { fileURLToPath } from 'url';
import { call_contract_function } from './test_helpers.js';
const __filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(__filename);
describe('Runtime Error', () => {
let keypair;
const server = new StellarSdk.SorobanRpc.Server(
"https://soroban-testnet.stellar.org:443",
);
let contractAddr;
let contract;
before(async () => {
console.log('Setting up runtime_error.sol contract tests...');
// read secret from file
const secret = readFileSync('alice.txt', 'utf8').trim();
keypair = StellarSdk.Keypair.fromSecret(secret);
let contractIdFile = path.join(dirname, '.soroban', 'contract-ids', 'Error.txt');
// read contract address from file
contractAddr = readFileSync(contractIdFile, 'utf8').trim().toString();
// load contract
contract = new StellarSdk.Contract(contractAddr);
// call decrement once. The second call however will result in a runtime error
await call_contract_function("decrement", server, keypair, contract);
});
it('get correct initial counter', async () => {
// decrement the counter again, resulting in a runtime error
let res = await call_contract_function("decrement", server, keypair, contract);
expect(res).to.contain('runtime_error: math overflow in runtime_error.sol:6:9-19');
});
});