-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds new 2wp file starting with one pegin test checking events, etc.
- Loading branch information
1 parent
916d696
commit 40f2ef5
Showing
5 changed files
with
146 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
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, btcToWeis } = require('@rsksmart/btc-eth-unit-converter'); | ||
const { waitAndUpdateBridge, mineAndSync } = require('../rsk-utils'); | ||
const { PEGIN_EVENTS } = require("../constants"); | ||
const { findAndCheckPeginBtcEventAtBlock } = require('../assertions/2wp'); | ||
const { sendPegin, | ||
ensurePeginIsRegistered, | ||
donateToBridge, | ||
createSenderRecipientInfo, | ||
createExpectedPeginBtcEvent | ||
} = require('../2wp-utils'); | ||
|
||
const DONATION_AMOUNT = 250; | ||
|
||
let btcTxHelper; | ||
let rskTxHelper; | ||
let rskTxHelpers; | ||
let bridge; | ||
let federationAddress; | ||
let minimumPeginValueInBtc; | ||
|
||
const setupBridgeDonation = async (rskTxHelpers, btcTxHelper) => { | ||
const donatingBtcAddressInformation = await btcTxHelper.generateBtcAddress('legacy'); | ||
await mineAndSync(rskTxHelpers); | ||
await btcTxHelper.fundAddress(donatingBtcAddressInformation.address, DONATION_AMOUNT + btcTxHelper.getFee()); | ||
await donateToBridge(rskTxHelpers[0], btcTxHelper, donatingBtcAddressInformation, DONATION_AMOUNT); | ||
}; | ||
|
||
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(); | ||
const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call(); | ||
minimumPeginValueInBtc = Number(satoshisToBtc(minimumPeginValueInSatoshis)); | ||
|
||
await btcTxHelper.importAddress(federationAddress, 'federation'); | ||
await waitAndUpdateBridge(rskTxHelper); | ||
await setupBridgeDonation(rskTxHelpers, btcTxHelper); | ||
|
||
}); | ||
|
||
it('should transfer BTC to RBTC', async () => { | ||
|
||
// Arrange | ||
|
||
const senderInfo = await createSenderRecipientInfo(rskTxHelper, btcTxHelper); | ||
const initialFederationAddressBalanceInBtc = Number(await btcTxHelper.getAddressBalance(federationAddress)); | ||
const initialSenderAddressBalanceInBtc = Number(await btcTxHelper.getAddressBalance(senderInfo.btcSenderAddressInfo.address)); | ||
const initialRskRecipientBalance = Number(await rskTxHelper.getBalance(senderInfo.rskRecipientRskAddressInfo.address)); | ||
|
||
// Act | ||
|
||
const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, senderInfo.btcSenderAddressInfo, minimumPeginValueInBtc); | ||
await ensurePeginIsRegistered(rskTxHelper, btcPeginTxHash); | ||
|
||
// Assert | ||
|
||
const isBtcTxHashAlreadyProcessed = await bridge.methods.isBtcTxHashAlreadyProcessed(btcPeginTxHash).call(); | ||
expect(isBtcTxHashAlreadyProcessed).to.be.true; | ||
|
||
const expectedEvent = createExpectedPeginBtcEvent(PEGIN_EVENTS.PEGIN_BTC, senderInfo.rskRecipientRskAddressInfo.address, btcPeginTxHash, minimumPeginValueInBtc, '0'); | ||
const btcTxHashProcessedHeight = Number(await bridge.methods.getBtcTxHashProcessedHeight(btcPeginTxHash).call()); | ||
await findAndCheckPeginBtcEventAtBlock(rskTxHelper, btcTxHashProcessedHeight, expectedEvent); | ||
|
||
const finalFederationAddressBalanceInBtc = Number(await btcTxHelper.getAddressBalance(federationAddress)); | ||
expect(finalFederationAddressBalanceInBtc).to.be.equal(initialFederationAddressBalanceInBtc + minimumPeginValueInBtc); | ||
|
||
const finalSenderAddressBalanceInBtc = Number(await btcTxHelper.getAddressBalance(senderInfo.btcSenderAddressInfo.address)); | ||
expect(finalSenderAddressBalanceInBtc).to.be.equal(initialSenderAddressBalanceInBtc - minimumPeginValueInBtc - btcTxHelper.getFee()); | ||
|
||
const finalRskRecipientBalance = Number(await rskTxHelper.getBalance(senderInfo.rskRecipientRskAddressInfo.address)); | ||
expect(finalRskRecipientBalance).to.be.equal(initialRskRecipientBalance + Number(btcToWeis(minimumPeginValueInBtc))); | ||
|
||
}); | ||
|
||
}); | ||
|
||
} | ||
|
||
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-new'); | ||
|
||
twoWpTests.execute('BTC <=> RSK 2WP', () => Runners.hosts.federate.host); |