Skip to content

Commit

Permalink
Adds 'should reject a basic pegin v1 with value exactly below minimum…
Browse files Browse the repository at this point in the history
…' test
  • Loading branch information
jeremy-then committed Sep 25, 2024
1 parent efd57b8 commit 737bb82
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions lib/tests/2wp.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,59 @@ const execute = (description, getRskHost) => {

});

it('should reject a basic pegin v1 with value exactly below minimum', async () => {

// Arrange

const initialFederationAddressBalanceInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, federationAddress);
const senderRecipientInfo = await createSenderRecipientInfo(rskTxHelper, btcTxHelper);
const initialSenderAddressBalanceInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, senderRecipientInfo.btcSenderAddressInfo.address);
// The minimum pegin value minus 1 satoshis
const peginValueInSatoshis = minimumPeginValueInSatoshis - 1;
const peginV1RskRecipientAddress = await rskTxHelper.newAccountWithSeed('');

// Act

const peginV1Data = [Buffer.from(createPeginV1TxData(peginV1RskRecipientAddress), 'hex')];

const blockNumberBeforePegin = await rskTxHelper.getBlockNumber();

const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, senderRecipientInfo.btcSenderAddressInfo, satoshisToBtc(peginValueInSatoshis), peginV1Data);
// Funds of a pegin with value below minimum are lost. But calling triggerRelease here to ensure that nothing will be refunded.
await triggerRelease(rskTxHelpers, btcTxHelper);

// Assert

// The btc pegin tx is not marked as processed by the bridge
const isBtcTxHashAlreadyProcessed = await bridge.methods.isBtcTxHashAlreadyProcessed(btcPeginTxHash).call();
expect(isBtcTxHashAlreadyProcessed).to.be.false;
const btcTxHashProcessedHeight = Number(await bridge.methods.getBtcTxHashProcessedHeight(btcPeginTxHash).call());
expect(btcTxHashProcessedHeight).to.be.equal(-1);

// The rejected_pegin event is emitted with the expected values
const expectedEvent = createExpectedRejectedPeginEvent(PEGIN_EVENTS.REJECTED_PEGIN, btcPeginTxHash, PEGIN_REJECTION_REASONS.INVALID_AMOUNT);
const currentBlockNumber = await rskTxHelper.getBlockNumber();
const peginBtcEvent = await findEventInBlock(rskTxHelper, expectedEvent.name, blockNumberBeforePegin, currentBlockNumber);
expect(peginBtcEvent).to.be.deep.equal(expectedEvent);

// The federation balance is increased by the pegin value
const finalFederationAddressBalanceInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, federationAddress);
expect(finalFederationAddressBalanceInSatoshis).to.be.equal(initialFederationAddressBalanceInSatoshis + peginValueInSatoshis);

// The sender address balance is decreased by the pegin value and the btc fee
const finalSenderAddressBalanceInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, senderRecipientInfo.btcSenderAddressInfo.address);
expect(finalSenderAddressBalanceInSatoshis).to.be.equal(initialSenderAddressBalanceInSatoshis - peginValueInSatoshis - btcFeeInSatoshis);

// The sender derived rsk address rsk address balance is unchanged
const finalSenderDerivedRskAddressBalance = Number(await rskTxHelper.getBalance(senderRecipientInfo.rskRecipientRskAddressInfo.address));
expect(finalSenderDerivedRskAddressBalance).to.be.equal(0);

// The pegin v1 rsk recipient address is also zero
const finalRskRecipientBalance = Number(await rskTxHelper.getBalance(peginV1RskRecipientAddress));
expect(finalRskRecipientBalance).to.be.equal(0);

});

});

}
Expand Down

0 comments on commit 737bb82

Please sign in to comment.