-
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.
getBlockHeader() part, test encapsulation
- Loading branch information
1 parent
0c30e59
commit 145f475
Showing
9 changed files
with
128 additions
and
5,280 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const expect = require('chai').expect; | ||
const { getRskTransactionHelper } = require('../rsk-tx-helper-provider'); | ||
const { getBtcClient } = require('../btc-client-provider'); | ||
const { getBridge, getLatestActiveForkName } = require('../precompiled-abi-forks-util'); | ||
const { activateFork, sendTxWithCheck, getLatestForkName } = require('../rsk-utils'); | ||
const { ensure0x } = require('../utils'); | ||
|
||
let rskTxHelper; | ||
let btcTxHelper; | ||
let bridge; | ||
|
||
const fulfillRequirementsToRunAsSingleTestFile = async () => { | ||
const forkName = process.env.FORK_NAME || getLatestForkName().name; | ||
await activateFork(Runners.common.forks[forkName]); | ||
}; | ||
|
||
const execute = (description, getRskHost) => { | ||
describe(description, function() { | ||
before(async () => { | ||
rskTxHelper = getRskTransactionHelper(getRskHost()); | ||
btcTxHelper = getBtcClient(); | ||
|
||
if(process.env.RUNNING_SINGLE_TEST_FILE) { | ||
await fulfillRequirementsToRunAsSingleTestFile(); | ||
} | ||
|
||
bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); | ||
}); | ||
|
||
it('should return 0 and increment BTC blockchain size when calling receiveHeader method', async () => { | ||
const cowAddress = await rskTxHelper.newAccountWithSeed('cow'); | ||
const blockHashes = await btcTxHelper.mine(); | ||
const blockHeader = await btcTxHelper.getBlockHeader(blockHashes[0], false); | ||
const blockchainInitialHeigth = await bridge.methods.getBtcBlockchainBestChainHeight().call(); | ||
|
||
await sendTxWithCheck( | ||
rskTxHelper, | ||
bridge.methods.receiveHeader(ensure0x(blockHeader)), | ||
cowAddress, | ||
(result) => { expect(Number(result)).to.be.equal(0) } | ||
); | ||
const blockchainFinalHeight = await bridge.methods.getBtcBlockchainBestChainHeight().call(); | ||
expect(Number(blockchainFinalHeight)).to.be.equal(Number(blockchainInitialHeigth) + 1); | ||
}); | ||
|
||
it('should return -1 when calling receiveHeader method consecutively', async () => { | ||
const blockHashes = await btcTxHelper.mine(); | ||
const blockHeader = await btcTxHelper.getBlockHeader(blockHashes[0], false); | ||
const result = await bridge.methods.receiveHeader([ensure0x(blockHeader)]).call() | ||
expect(result).to.be.equal('-1'); | ||
} | ||
); | ||
}); | ||
}; | ||
|
||
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,53 @@ | ||
const expect = require('chai').expect; | ||
const { getRskTransactionHelper } = require('../rsk-tx-helper-provider'); | ||
const { getBtcClient } = require('../btc-client-provider'); | ||
const { getBridge, getLatestActiveForkName } = require('../precompiled-abi-forks-util'); | ||
const { activateFork, sendTxWithCheck, getLatestForkName } = require('../rsk-utils'); | ||
const { ensure0x } = require('../utils'); | ||
|
||
let rskTxHelper; | ||
let btcTxHelper; | ||
|
||
/** | ||
* Takes the blockchain to the required state for this test file to run in isolation. | ||
*/ | ||
const fulfillRequirementsToRunAsSingleTestFile = async () => { | ||
const forkName = process.env.FORK_NAME || getLatestForkName().name; | ||
await activateFork(Runners.common.forks[forkName]); | ||
}; | ||
|
||
const execute = (description, getRskHost) => { | ||
describe(description, function() { | ||
|
||
before(async () => { | ||
rskTxHelper = getRskTransactionHelper(getRskHost()); | ||
btcTxHelper = getBtcClient(); | ||
|
||
if(process.env.RUNNING_SINGLE_TEST_FILE) { | ||
await fulfillRequirementsToRunAsSingleTestFile(); | ||
} | ||
}); | ||
|
||
it('Calling receiveHeaders method with regular user should not increment BTC blockchain size', async () => { | ||
const bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName()); | ||
const blockNumberInitial = await bridge.methods.getBtcBlockchainBestChainHeight().call(); | ||
const cowAddress = await rskTxHelper.newAccountWithSeed('cow'); | ||
const blockHashes = await btcTxHelper.mine(); | ||
const blockHeader = await btcTxHelper.getBlockHeader(blockHashes[0], false); | ||
|
||
await sendTxWithCheck( | ||
rskTxHelper, | ||
bridge.methods.receiveHeaders([ensure0x(blockHeader)]), | ||
cowAddress, | ||
(result) => { expect(result).to.be.empty } | ||
); | ||
|
||
const blockNumberFinal = await bridge.methods.getBtcBlockchainBestChainHeight().call(); | ||
expect(blockNumberInitial).to.be.equal(blockNumberFinal); | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
execute, | ||
}; |
Oops, something went wrong.