-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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,54 @@ 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 | ||
|
||
const expectedCountOfThisPeginUtxosInTheBridge = 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. maybe this could be the default value for the param in 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 is. I just wanted to express it explicitly here. I can remove it and use it like this for multiple utxos. 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. Removed. |
||
await ensurePeginIsRegistered(rskTxHelper, btcPeginTxHash, expectedCountOfThisPeginUtxosInTheBridge); | ||
|
||
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) => { | ||
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); | ||
|
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.