-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds simple peginv1 test #106
Merged
marcos-iov
merged 2 commits into
rits-refactors-9-2024-integration
from
add-simple-peginv1-test
Oct 2, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
const expect = require('chai').expect; | ||
const BN = require('bn.js'); | ||
const { createPeginV1TxData } = require('pegin-address-verificator'); | ||
const { getBridge } = require('../precompiled-abi-forks-util'); | ||
const { getBtcClient } = require('../btc-client-provider'); | ||
const { getRskTransactionHelper } = require('../rsk-tx-helper-provider'); | ||
|
@@ -34,7 +35,7 @@ const execute = (description, getRskHost) => { | |
|
||
federationAddress = await bridge.methods.getFederationAddress().call(); | ||
minimumPeginValueInSatoshis = Number(await bridge.methods.getMinimumLockTxValue().call()); | ||
btcFeeInSatoshis = btcToSatoshis(await btcTxHelper.getFee()); | ||
btcFeeInSatoshis = Number(btcToSatoshis(await btcTxHelper.getFee())); | ||
|
||
await btcTxHelper.importAddress(federationAddress, 'federation'); | ||
|
||
|
@@ -105,13 +106,53 @@ const execute = (description, getRskHost) => { | |
|
||
}); | ||
|
||
it('should do a basic pegin v1 with the exact minimum value', async () => { | ||
|
||
// Arrange | ||
|
||
const initial2wpBalances = await get2wpBalances(rskTxHelper, btcTxHelper); | ||
const senderRecipientInfo = await createSenderRecipientInfo(rskTxHelper, btcTxHelper); | ||
const initialSenderAddressBalanceInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, senderRecipientInfo.btcSenderAddressInfo.address); | ||
const peginValueInSatoshis = minimumPeginValueInSatoshis; | ||
const peginV1RskRecipientAddress = await rskTxHelper.newAccountWithSeed(''); | ||
|
||
// Act | ||
|
||
const peginV1Data = [Buffer.from(createPeginV1TxData(peginV1RskRecipientAddress), 'hex')]; | ||
|
||
const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, senderRecipientInfo.btcSenderAddressInfo, Number(satoshisToBtc(peginValueInSatoshis)), peginV1Data); | ||
|
||
// Assert | ||
|
||
await ensurePeginIsRegistered(rskTxHelper, btcPeginTxHash); | ||
|
||
const expectedPeginProtocolVersion = '1'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It defaults to '0', at the |
||
await assertExpectedPeginBtcEventIsEmitted(btcPeginTxHash, peginV1RskRecipientAddress, peginValueInSatoshis, expectedPeginProtocolVersion); | ||
|
||
await assert2wpBalancesAfterSuccessfulPegin(initial2wpBalances, 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 finalSenderDerivedRskAddressBalanceInWeisBN = await rskTxHelper.getBalance(senderRecipientInfo.rskRecipientRskAddressInfo.address); | ||
expect(finalSenderDerivedRskAddressBalanceInWeisBN.eq(new BN('0'))).to.be.true; | ||
|
||
// The pegin v1 rsk recipient address has the funds | ||
const finalRskRecipientBalanceInWeisBN = await rskTxHelper.getBalance(peginV1RskRecipientAddress); | ||
const expectedFinalRskRecipientBalanceInWeisBN = new BN(satoshisToWeis(peginValueInSatoshis)); | ||
expect(finalRskRecipientBalanceInWeisBN.eq(expectedFinalRskRecipientBalanceInWeisBN)).to.be.true; | ||
|
||
}); | ||
|
||
}); | ||
|
||
} | ||
|
||
const assertExpectedPeginBtcEventIsEmitted = async (btcPeginTxHash, rskRecipientAddress, peginValueInSatoshis) => { | ||
const assertExpectedPeginBtcEventIsEmitted = async (btcPeginTxHash, rskRecipientAddress, peginValueInSatoshis, expectedPeginProtocolVersion = '0') => { | ||
const recipient1RskAddressChecksumed = rskTxHelper.getClient().utils.toChecksumAddress(ensure0x(rskRecipientAddress)); | ||
const expectedEvent = createExpectedPeginBtcEvent(PEGIN_EVENTS.PEGIN_BTC, recipient1RskAddressChecksumed, btcPeginTxHash, peginValueInSatoshis); | ||
const expectedEvent = createExpectedPeginBtcEvent(PEGIN_EVENTS.PEGIN_BTC, recipient1RskAddressChecksumed, btcPeginTxHash, peginValueInSatoshis, expectedPeginProtocolVersion); | ||
const btcTxHashProcessedHeight = Number(await bridge.methods.getBtcTxHashProcessedHeight(btcPeginTxHash).call()); | ||
const peginBtcEvent = await findEventInBlock(rskTxHelper, expectedEvent.name, btcTxHashProcessedHeight); | ||
expect(peginBtcEvent).to.be.deep.equal(expectedEvent); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's under your radar. But we should also have some tests that add the btc refund address to the op return payload.
Nothing will change since there won't be a refund, but we should check that the peg-in still works when we add that data.
And then some tests with invalid payloads, including invalid refund address data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.