Skip to content

Commit

Permalink
Adds 'should reject and refund a legacy pegin from a multisig account…
Browse files Browse the repository at this point in the history
… with the value exactly minimum' test
  • Loading branch information
jeremy-then committed Sep 25, 2024
1 parent 737bb82 commit f0c37e5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const FUNDS_MIGRATION_AGE_SINCE_ACTIVATION_END = 150;

const PEGIN_REJECTION_REASONS = {
PEGIN_CAP_SURPASSED_REASON: '1',
LEGACY_PEGIN_MULTISIG_SENDER: '2',
PEGIN_V1_INVALID_PAYLOAD_REASON: '4',
INVALID_AMOUNT: '5',
};
Expand Down
49 changes: 48 additions & 1 deletion lib/tests/2wp.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const execute = (description, getRskHost) => {
federationAddress = await bridge.methods.getFederationAddress().call();
minimumPeginValueInSatoshis = Number(await bridge.methods.getMinimumLockTxValue().call());
minimumPeginValueInBtc = Number(satoshisToBtc(minimumPeginValueInSatoshis));
btcFeeInSatoshis = btcToSatoshis(await btcTxHelper.getFee());
btcFeeInSatoshis = Number(btcToSatoshis(await btcTxHelper.getFee()));

await btcTxHelper.importAddress(federationAddress, 'federation');
await waitAndUpdateBridge(rskTxHelper);
Expand Down Expand Up @@ -478,6 +478,53 @@ const execute = (description, getRskHost) => {

});

it('should reject and refund a legacy pegin from a multisig account with the value exactly minimum', async () => {

// Arrange

const initialFederationAddressBalanceInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, federationAddress);

const multisigSenderAddressInfo = await btcTxHelper.generateMultisigAddress(3, 2, 'legacy');
const peginValueInSatoshis = minimumPeginValueInSatoshis;
await btcTxHelper.fundAddress(multisigSenderAddressInfo.address, satoshisToBtc(peginValueInSatoshis + btcFeeInSatoshis));

// Act

const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, multisigSenderAddressInfo, satoshisToBtc(peginValueInSatoshis));

// Assert

// The btc pegin tx is marked as processed by the bridge.
const isBtcTxHashAlreadyProcessed = await bridge.methods.isBtcTxHashAlreadyProcessed(btcPeginTxHash).call();
expect(isBtcTxHashAlreadyProcessed).to.be.true;

// The rejected_pegin event is emitted with the expected values
const btcTxHashProcessedHeight = Number(await bridge.methods.getBtcTxHashProcessedHeight(btcPeginTxHash).call());
const expectedEvent = createExpectedRejectedPeginEvent(PEGIN_EVENTS.REJECTED_PEGIN, btcPeginTxHash, PEGIN_REJECTION_REASONS.LEGACY_PEGIN_MULTISIG_SENDER);
const peginBtcEvent = await findEventInBlock(rskTxHelper, expectedEvent.name, btcTxHashProcessedHeight);
expect(peginBtcEvent).to.be.deep.equal(expectedEvent);

// Expecting the federation balance to have increased by the pegin value up to this point.
const federationAddressBalanceAfterPeginInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, federationAddress);
expect(federationAddressBalanceAfterPeginInSatoshis).to.be.equal(initialFederationAddressBalanceInSatoshis + peginValueInSatoshis);

// Expecting the btc sender balance to be zero after the pegin.
const senderAddressBalanceAfterPegin = await getBtcAddressBalanceInSatoshis(btcTxHelper, multisigSenderAddressInfo.address);
expect(Number(senderAddressBalanceAfterPegin)).to.be.equal(0);

// We are expecting a refund pegout to go through. So, let's push it.
await triggerRelease(rskTxHelpers, btcTxHelper);

// Now, after our expected refund, the federation balance should have decreased by the pegin amount, meaning, should have its initial balance.
const finalFederationAddressBalanceInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, federationAddress);
expect(finalFederationAddressBalanceInSatoshis).to.be.equal(initialFederationAddressBalanceInSatoshis)

// Finally, the multisig sender address should have received the funds back minus certain fee.
const finalSenderAddressBalanceInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, multisigSenderAddressInfo.address);
expect(finalSenderAddressBalanceInSatoshis).to.be.above(peginValueInSatoshis - btcFeeInSatoshis).and.below(peginValueInSatoshis)

});

});

}
Expand Down

0 comments on commit f0c37e5

Please sign in to comment.