Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Catch error and reject() in testEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
raykyri committed Jun 3, 2021
1 parent 3874f3f commit 0504962
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions web3tests/testEvent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { assert } = require('chai');
const Web3 = require('web3');
const EventContract = require('../build/contracts/EventContract.json');
const { deployContract, account, initWeb3, privKey } = require('../utils');
const { deployContract, account, initWeb3, privKey, GAS_PRICE, GAS_LIMIT } = require('../utils');
const sub_account = '0x6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b';
const contract = require("@truffle/contract");

Expand All @@ -28,7 +28,7 @@ describe("EventContract test", async () => {
const cAddress = c._address;

// init subscription
await new Promise(async (resolve) => {
await new Promise(async (resolve, reject) => {
c.events.allEvents((error, data) => {
assert.equal(data.event, 'e');
assert.equal(data.address, cAddress);
Expand All @@ -38,7 +38,10 @@ describe("EventContract test", async () => {
assert.equal(data.address, cAddress);
resolve();
})
.on('error', console.error);
.on('error', (err) => {
console.error(err);
reject();
});

// initialize another web3 connection with dev signer and fire tx'es to subscribe to
const anotherWeb3 = initWeb3();
Expand All @@ -47,8 +50,13 @@ describe("EventContract test", async () => {
unlinked_binary: EventContract.bytecode,
});
EC.setProvider(anotherWeb3.currentProvider);
const cc = await EC.at(cAddress);
const tx = await cc.emitEvent({ from: account });
try {
const cc = await EC.at(cAddress);
const tx = await cc.emitEvent({ from: account });
} catch (err) {
console.error(err);
reject(err);
}
});
})
});

0 comments on commit 0504962

Please sign in to comment.