Skip to content

Commit

Permalink
Asserting events.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-then committed Jan 14, 2025
1 parent c5f6867 commit 1c08eb9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
10 changes: 10 additions & 0 deletions config/node-configs/rsk-reg-1.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ federator {
}

rpc {
providers : {
web: {
cors: "*",
http: {
enabled: true,
bind_address = "0.0.0.0",
hosts = ["localhost"]
}
}
}
# Enabled RPC Modules. If the module is NOT in the list, and mark as "enabled", the rpc calls will be discard.
modules = [
{
Expand Down
10 changes: 10 additions & 0 deletions config/node-configs/rsk-reg-2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ federator {
}

rpc {
providers : {
web: {
cors: "*",
http: {
enabled: true,
bind_address = "0.0.0.0",
hosts = ["localhost"]
}
}
}
# Enabled RPC Modules. If the module is NOT in the list, and mark as "enabled", the rpc calls will be discard.
modules = [
{
Expand Down
10 changes: 10 additions & 0 deletions config/node-configs/rsk-reg-3.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ federator {
}

rpc {
providers : {
web: {
cors: "*",
http: {
enabled: true,
bind_address = "0.0.0.0",
hosts = ["localhost"]
}
}
}
# Enabled RPC Modules. If the module is NOT in the list, and mark as "enabled", the rpc calls will be discard.
modules = [
{
Expand Down
5 changes: 4 additions & 1 deletion lib/rsk-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ const sendTxWithCheck = async (rskTxHelper, method, from, checkCallback) => {
* @returns {BridgeEvent} event
*/
const findEventInBlock = async (rskTxHelper, eventName, fromBlockHashOrBlockNumber, toBlockHashOrBlockNumber, check) => {
if(typeof eventName !== 'string') {
throw new Error('`eventName` parameter must be a string. It is of type: ' + typeof eventName);
}
if(!fromBlockHashOrBlockNumber) {
fromBlockHashOrBlockNumber = await rskTxHelper.getBlockNumber();
}
Expand Down Expand Up @@ -477,7 +480,7 @@ const findBridgeTransactionsInThisBlock = async (web3Client, blockHashOrBlockNum
// const bridgeTransactionParser = new BridgeTransactionParser(web3Client);
// return bridgeTransactionParser.getBridgeTransactionsInThisBlock(blockHashOrBlockNumber);

return bridgeTxParser.getBridgeTransactionsInThisBlock(blockHashOrBlockNumber);
return await bridgeTxParser.getBridgeTransactionsInThisBlock(blockHashOrBlockNumber);
}

/**
Expand Down
25 changes: 21 additions & 4 deletions tests/00_00_04-change-federation.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const {
ensurePeginIsRegistered
} = require('../lib/2wp-utils');
const { getBtcClient } = require('../lib/btc-client-provider');
const { MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS } = require('../lib/constants/pegout-constants');
const { MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS, PEGOUT_EVENTS } = require('../lib/constants/pegout-constants');
const {
getActiveFederationKeys,
getProposedFederationInfo,
Expand Down Expand Up @@ -302,7 +302,8 @@ describe('Change federation', async function() {

const pegoutCreationBlockNumber = Number(svpPegoutWaitingForConfirmations.pegoutCreationBlockNumber);

expect(pegoutCreationBlockNumber).to.be.equal(commitFederationCreationBlockNumber + 1, 'The svp fund tx pegout creation block number should be the block that contains the first updateCollections call right after the commitFederation call.');
const expectedPegoutCreationBlockNumber = commitFederationCreationBlockNumber + 1;
expect(pegoutCreationBlockNumber).to.be.equal(expectedPegoutCreationBlockNumber, 'The svp fund tx pegout creation block number should be the block that contains the first updateCollections call right after the commitFederation call.');

const rawSvpBtcTransaction = svpPegoutWaitingForConfirmations.btcRawTx;

Expand All @@ -327,12 +328,28 @@ describe('Change federation', async function() {
expect(actualActiveFederationAddress).to.be.equal(initialFederationAddress, 'The active federation address in the SVP fund transaction should be the third output.');

// The proposed federation and flyover addresses output values should be double the minimum pegout value.
expect(proposedFederationOutput.value).to.be.equal(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS * 2, 'The proposed federation output value should be double the minimum pegout value.');
expect(flyoverOutput.value).to.be.equal(MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS * 2, 'The flyover output value should be double the minimum pegout value.');
const expectedProposedFederationOutputValue = MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS * 2;
expect(proposedFederationOutput.value).to.be.equal(expectedProposedFederationOutputValue, 'The proposed federation output value should be double the minimum pegout value.');
const expectedFlyoverOutputValue = MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS * 2;
expect(flyoverOutput.value).to.be.equal(expectedFlyoverOutputValue, 'The flyover output value should be double the minimum pegout value.');

// Only the svp fund tx hash unsigned value should be in storage
await assertOnlySvpFundTxHashUnsignedIsInStorage(rskTxHelper, btcTransaction.getId());

// The release_requested event should be emitted with the expected values
const releaseRequestedEvent = await rskUtils.findEventInBlock(rskTxHelper, PEGOUT_EVENTS.RELEASE_REQUESTED.name, expectedPegoutCreationBlockNumber);
const expectedReleaseRequestedAmount = expectedProposedFederationOutputValue + expectedFlyoverOutputValue;
expect(Number(releaseRequestedEvent.arguments.amount)).to.be.equal(expectedReleaseRequestedAmount, 'The amount in the release requested event should be the sum of the proposed federation and flyover output values.');
expect(releaseRequestedEvent, 'The release requested event should be emitted.').to.not.be.null;
expect(removePrefix0x(releaseRequestedEvent.arguments.btcTxHash)).to.be.equal(btcTransaction.getId(), 'The btc tx hash in the release requested event should be the tx id of the SVP fund tx.');

// The pegout_transaction_created event should be emitted with the expected values
const pegoutTransactionCreatedEvent = await rskUtils.findEventInBlock(rskTxHelper, PEGOUT_EVENTS.PEGOUT_TRANSACTION_CREATED.name, expectedPegoutCreationBlockNumber);
expect(pegoutTransactionCreatedEvent, 'The pegout transaction created event should be emitted.').to.not.be.null;
expect(removePrefix0x(pegoutTransactionCreatedEvent.arguments.btcTxHash)).to.be.equal(btcTransaction.getId(), 'The btc tx hash in the pegout transaction created event should be the tx id of the SVP fund tx.');

// TODO: assert utxoOutpointValues here?

});

it('should activate federation', async () => {
Expand Down

0 comments on commit 1c08eb9

Please sign in to comment.