runtime_error.spec.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import * as StellarSdk from '@stellar/stellar-sdk';
  2. import { readFileSync } from 'fs';
  3. import { expect } from 'chai';
  4. import path from 'path';
  5. import { fileURLToPath } from 'url';
  6. import { call_contract_function } from './test_helpers.js';
  7. const __filename = fileURLToPath(import.meta.url);
  8. const dirname = path.dirname(__filename);
  9. describe('Runtime Error', () => {
  10. let keypair;
  11. const server = new StellarSdk.SorobanRpc.Server(
  12. "https://soroban-testnet.stellar.org:443",
  13. );
  14. let contractAddr;
  15. let contract;
  16. before(async () => {
  17. console.log('Setting up runtime_error.sol contract tests...');
  18. // read secret from file
  19. const secret = readFileSync('alice.txt', 'utf8').trim();
  20. keypair = StellarSdk.Keypair.fromSecret(secret);
  21. let contractIdFile = path.join(dirname, '.soroban', 'contract-ids', 'Error.txt');
  22. // read contract address from file
  23. contractAddr = readFileSync(contractIdFile, 'utf8').trim().toString();
  24. // load contract
  25. contract = new StellarSdk.Contract(contractAddr);
  26. // call decrement once. The second call however will result in a runtime error
  27. await call_contract_function("decrement", server, keypair, contract);
  28. });
  29. it('prints error', async () => {
  30. // decrement the counter again, resulting in a runtime error
  31. let res = await call_contract_function("decrement", server, keypair, contract);
  32. expect(res).to.contain('runtime_error: math overflow in runtime_error.sol:6:9-19');
  33. });
  34. });