-
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 new 2wp file starting with one pegin test checking event #87
Merged
marcos-iov
merged 10 commits into
rits-refactors-9-2024-integration
from
create-new-2wp-file
Sep 25, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0977110
Adds new 2wp file starting with one pegin test checking events, etc.
jeremy-then d22bb7e
Updates doc comment return type on donateToBridge.
jeremy-then 8d38069
Renames find and check event function.
jeremy-then f530baa
Adds doc comments.
jeremy-then 13bf6a7
Refactors to use satoshis. Renames.
jeremy-then e136ffe
Renames tests
jeremy-then a81d285
Using peginValueInSatoshis for the createExpectedPeginBtcEvent
jeremy-then 58deab1
Asserting that the bridge own balance and bridge utxos sum is as expe…
jeremy-then 955ad29
Moves getBridgeUtxosBalance function to 2wp-utils.js
jeremy-then d4fe6d9
Updates getBridgeUtxosBalance doc comment
jeremy-then 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
const expect = require('chai').expect; | ||
const { getBridge } = require('../precompiled-abi-forks-util'); | ||
const { getBtcClient } = require('../btc-client-provider'); | ||
const { getRskTransactionHelpers, getRskTransactionHelper } = require('../rsk-tx-helper-provider'); | ||
const { satoshisToBtc, btcToSatoshis, satoshisToWeis } = require('@rsksmart/btc-eth-unit-converter'); | ||
const { findEventInBlock } = require('../rsk-utils'); | ||
const { PEGIN_EVENTS } = require("../constants"); | ||
const { sendPegin, | ||
ensurePeginIsRegistered, | ||
createSenderRecipientInfo, | ||
createExpectedPeginBtcEvent, | ||
BRIDGE_ADDRESS, | ||
getBridgeUtxosBalance, | ||
} = require('../2wp-utils'); | ||
const { ensure0x } = require('../utils'); | ||
const { getBtcAddressBalanceInSatoshis } = require('../btc-utils'); | ||
|
||
let btcTxHelper; | ||
let rskTxHelper; | ||
let rskTxHelpers; | ||
let bridge; | ||
let federationAddress; | ||
let minimumPeginValueInSatoshis; | ||
let minimumPeginValueInBtc; | ||
let btcFeeInSatoshis; | ||
|
||
const execute = (description, getRskHost) => { | ||
|
||
describe(description, () => { | ||
|
||
before(async () => { | ||
|
||
rskTxHelpers = getRskTransactionHelpers(); | ||
btcTxHelper = getBtcClient(); | ||
rskTxHelper = getRskTransactionHelper(getRskHost()); | ||
bridge = getBridge(rskTxHelper.getClient()); | ||
|
||
federationAddress = await bridge.methods.getFederationAddress().call(); | ||
minimumPeginValueInSatoshis = Number(await bridge.methods.getMinimumLockTxValue().call()); | ||
minimumPeginValueInBtc = Number(satoshisToBtc(minimumPeginValueInSatoshis)); | ||
btcFeeInSatoshis = btcToSatoshis(await btcTxHelper.getFee()); | ||
|
||
await btcTxHelper.importAddress(federationAddress, 'federation'); | ||
|
||
}); | ||
|
||
it('should do a basic legacy pegin with the exact minimum value', async () => { | ||
|
||
// Arrange | ||
|
||
const initialBridgeBalance = Number(await rskTxHelper.getBalance(BRIDGE_ADDRESS)); | ||
const initialBridgeUtxosBalance = await getBridgeUtxosBalance(rskTxHelper); | ||
const initialFederationAddressBalanceInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, federationAddress); | ||
const senderRecipientInfo = await createSenderRecipientInfo(rskTxHelper, btcTxHelper); | ||
const initialSenderAddressBalanceInSatoshis = await getBtcAddressBalanceInSatoshis(btcTxHelper, senderRecipientInfo.btcSenderAddressInfo.address); | ||
const peginValueInSatoshis = minimumPeginValueInSatoshis; | ||
|
||
// Act | ||
|
||
const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, senderRecipientInfo.btcSenderAddressInfo, satoshisToBtc(peginValueInSatoshis)); | ||
await ensurePeginIsRegistered(rskTxHelper, btcPeginTxHash); | ||
|
||
// Assert | ||
|
||
// The btc pegin tx is already marked as processed by the bridge | ||
const isBtcTxHashAlreadyProcessed = await bridge.methods.isBtcTxHashAlreadyProcessed(btcPeginTxHash).call(); | ||
expect(isBtcTxHashAlreadyProcessed).to.be.true; | ||
|
||
// The pegin_btc event is emitted with the expected values | ||
const recipient1RskAddressChecksumed = rskTxHelper.getClient().utils.toChecksumAddress(ensure0x(senderRecipientInfo.rskRecipientRskAddressInfo.address)); | ||
const expectedEvent = createExpectedPeginBtcEvent(PEGIN_EVENTS.PEGIN_BTC, recipient1RskAddressChecksumed, btcPeginTxHash, peginValueInSatoshis); | ||
const btcTxHashProcessedHeight = Number(await bridge.methods.getBtcTxHashProcessedHeight(btcPeginTxHash).call()); | ||
const peginBtcEvent = await findEventInBlock(rskTxHelper, expectedEvent.name, btcTxHashProcessedHeight); | ||
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 recipient rsk address balance is increased by the pegin value | ||
const finalRskRecipientBalance = Number(await rskTxHelper.getBalance(senderRecipientInfo.rskRecipientRskAddressInfo.address)); | ||
expect(finalRskRecipientBalance).to.be.equal(Number(satoshisToWeis(peginValueInSatoshis))); | ||
|
||
// After the successful pegin, the Bridge balance should be reduced by the pegin value | ||
const finalBridgeBalance = Number(await rskTxHelper.getBalance(BRIDGE_ADDRESS)); | ||
expect(finalBridgeBalance).to.be.equal(initialBridgeBalance - satoshisToWeis(peginValueInSatoshis)); | ||
|
||
// After the successful pegin, the Bridge utxos sum should be incremented by the pegin value | ||
const finalBridgeUtxosBalance = await getBridgeUtxosBalance(rskTxHelper); | ||
expect(finalBridgeUtxosBalance).to.be.equal(initialBridgeUtxosBalance + peginValueInSatoshis); | ||
|
||
}); | ||
|
||
}); | ||
|
||
} | ||
|
||
module.exports = { | ||
execute, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const twoWpTests = require('../lib/tests/2wp'); | ||
|
||
twoWpTests.execute('BTC <=> RSK 2WP', () => Runners.hosts.federate.host); |
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 for now, but I would consider splitting this file before it grows too much. 2wpConstants, BrideEvents, FedChangeConstants, etc