Skip to content

Commit

Permalink
add emit event
Browse files Browse the repository at this point in the history
  • Loading branch information
eonwarped committed Jul 7, 2021
1 parent 0be8cd3 commit 1a982ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 15 additions & 3 deletions libs/SmartContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,25 @@ class SmartContracts {
if (contractTicks.find(t => t.contract === contractName && t.action === tickAction)) {
return { logs: { errors: ['contract tick already registered'] } };
}
contractTicks.push({
const newContractTick = {
contract: contractName,
action: tickAction,
startRefBlock: refHiveBlockNumber + 1,
});
};
contractTicks.push(newContractTick);
await database.updateContractsConfig(contractsConfig);
return { logs: { errors: [], events: [] } };
return {
logs: {
errors: [],
events: [
{
contract: 'contract',
event: 'registerTick',
data: newContractTick,
},
],
},
};
} catch (e) {
return { logs: { errors: [`${e.name}: ${e.message}`] } };
}
Expand Down
4 changes: 4 additions & 0 deletions test/ticks.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ describe('ticks', function () {
await fixture.sendBlock(block);
await tableAsserts.assertNoErrorInLastBlock();

let res = await fixture.database.getLatestBlockInfo();
let txs = res.transactions;
assert.equal(txs[1].logs, `{"events":[{"contract":"contract","event":"registerTick","data":{"contract":"testtick","action":"tick","startRefBlock":${refBlockNumber + 1}}}]}`);

refBlockNumber = fixture.getNextRefBlockNumber();
const tickedActions = await getTickingActionsAtRefblock(refBlockNumber);
assert.equal(JSON.stringify(tickedActions), '["testtick.tick"]');
Expand Down

0 comments on commit 1a982ff

Please sign in to comment.