Skip to content

Commit 01746cc

Browse files
committed
Initial segwit test setup and debugging.
1 parent 2a69be0 commit 01746cc

File tree

7 files changed

+61
-6
lines changed

7 files changed

+61
-6
lines changed

lib/tests/activate-fork.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ const { getRskTransactionHelpers } = require('../rsk-tx-helper-provider');
66
const execute = (fork) => {
77

88
// Unskip when there is a new fork to be tested pre and post.
9-
describe.skip(`Activate ${fork.name} fork`, () => {
9+
describe(`Activate ${fork.name} fork`, () => {
1010

1111
it(`should mine blocks until reach ${fork.activationHeight}th block in order to activate the fork`, async () => {
1212
try {
1313
const rskTransactionHelpers = getRskTransactionHelpers();
1414
const currentBlockNumber = await rskTransactionHelpers[0].getBlockNumber();
15+
console.log(`Current block number: ${currentBlockNumber}`);
1516
expect(currentBlockNumber).to.be.below(fork.activationHeight);
1617

1718
// Mine until activation block plus one

lib/tests/change-federation.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,31 @@ const execute = (description, newFederationConfig) => {
174174

175175
newFederationBtcPublicKeys = newFederationPublicKeys.map(federator => federator[KEY_TYPE_BTC]);
176176

177+
const tbd800IsActive = await Runners.common.forks.tbd800.isAlreadyActive();
178+
179+
console.log(`tbd800IsActive: ${tbd800IsActive}`);
180+
177181
const expectedNewFederationErpRedeemScriptBuffer = redeemScriptParser.getP2shErpRedeemScript(newFederationBtcPublicKeys.map(key => removePrefix0x(key)), ERP_PUBKEYS, ERP_CSV_VALUE);
178182
expectedNewFederationErpRedeemScript = expectedNewFederationErpRedeemScriptBuffer.toString('hex');
179-
expectedNewFederationAddress = redeemScriptParser.getAddressFromRedeemScript('REGTEST', expectedNewFederationErpRedeemScriptBuffer);
183+
console.log(`Expected new federation ERP redeem script: ${expectedNewFederationErpRedeemScript}`);
184+
185+
expectedNewFederationAddress = tbd800IsActive ?
186+
redeemScriptParser.getP2shP2wshAddressFromRedeemScript('REGTEST', expectedNewFederationErpRedeemScriptBuffer)
187+
:
188+
redeemScriptParser.getAddressFromRedeemScript('REGTEST', expectedNewFederationErpRedeemScriptBuffer);
189+
190+
// const expectedNewSegwitFederationAddress = redeemScriptParser.getP2shP2wshAddressFromRedeemScript('REGTEST', expectedNewFederationErpRedeemScriptBuffer);
191+
192+
console.log(`expectedNewFederationAddress: ${expectedNewFederationAddress}`);
180193

181194
const flyoverNewFederationRedeemScript = redeemScriptParser.getFlyoverRedeemScript(expectedNewFederationErpRedeemScriptBuffer, FLYOVER_DERIVATION_HASH);
182-
expectedFlyoverAddress = redeemScriptParser.getAddressFromRedeemScript('REGTEST', flyoverNewFederationRedeemScript);
195+
196+
expectedFlyoverAddress = tbd800IsActive ?
197+
redeemScriptParser.getP2shP2wshAddressFromRedeemScript('REGTEST', flyoverNewFederationRedeemScript)
198+
:
199+
redeemScriptParser.getAddressFromRedeemScript('REGTEST', flyoverNewFederationRedeemScript);
200+
201+
console.log(`Expected flyover address: ${expectedFlyoverAddress}`);
183202

184203
initialActiveFederationInfo = await getActiveFederationInfo(bridge);
185204

@@ -250,6 +269,7 @@ const execute = (description, newFederationConfig) => {
250269
const commitFederationEvent = await rskUtils.findEventInBlock(rskTxHelper, FEDERATION_EVENTS.COMMIT_FEDERATION_FAILED.name, latestBlockNumber);
251270

252271
const proposedFederationRedeemScript = removePrefix0x(commitFederationEvent.arguments.proposedFederationRedeemScript);
272+
console.log(`Proposed federation redeem script: ${proposedFederationRedeemScript}`);
253273
expect(proposedFederationRedeemScript).to.be.equal(expectedNewFederationErpRedeemScript, 'The failed proposed federation redeem script should be the same as the expected one.');
254274

255275
const blockNumber = Number(commitFederationEvent.arguments.blockNumber);
@@ -451,6 +471,7 @@ const execute = (description, newFederationConfig) => {
451471
// Assert
452472

453473
// The SVP fund transaction should be created and put in waiting for confirmations.
474+
console.log('finalBridgeState.pegoutsWaitingForConfirmations: ', finalBridgeState.pegoutsWaitingForConfirmations);
454475
expect(finalBridgeState.pegoutsWaitingForConfirmations.length).to.be.equal(1, 'There should be one pegout waiting for confirmations.');
455476
expect(finalBridgeState.pegoutsWaitingForSignatures.length).to.be.equal(0, 'No pegout should be waiting for signatures.');
456477

@@ -462,8 +483,12 @@ const execute = (description, newFederationConfig) => {
462483
expect(pegoutCreationBlockNumber).to.be.equal(expectedPegoutCreationBlockNumber, 'The svp fund tx pegout creation block number should be the block that contains the first updateCollections call right after the commitFederation call.');
463484

464485
const rawSvpFundTransaction = svpFundTxWaitingForConfirmations.btcRawTx;
486+
487+
console.log('rawSvpFundTransaction: ', rawSvpFundTransaction);
465488

466489
const svpFundTransaction = bitcoinJsLib.Transaction.fromHex(rawSvpFundTransaction);
490+
491+
console.log('svpFundTransaction: ', svpFundTransaction);
467492

468493
expect(svpFundTransaction.outs.length).to.be.equal(3, 'The SVP fund transaction should have 3 outputs.');
469494

@@ -490,6 +515,8 @@ const execute = (description, newFederationConfig) => {
490515
const expectedFlyoverOutputValue = MINIMUM_PEGOUT_AMOUNT_IN_SATOSHIS * 2;
491516
expect(proposedFederationFlyoverOutput.value).to.be.equal(expectedFlyoverOutputValue, 'The flyover output value should be double the minimum pegout value.');
492517

518+
console.log('svpFundTransaction.getId(): ', svpFundTransaction.getId());
519+
493520
// Only the svp fund tx hash unsigned value should be in storage
494521
await assertOnlySvpFundTxHashUnsignedIsInStorage(rskTxHelper, svpFundTransaction.getId());
495522

@@ -511,6 +538,9 @@ const execute = (description, newFederationConfig) => {
511538

512539
it('should release and register the svp fund transaction and create the svp spend transaction', async function () {
513540

541+
const latestBlockNumber1 = await rskTxHelper.getBlockNumber();
542+
console.log(`Latest block number before svp spend tx creation: ${latestBlockNumber1}`);
543+
514544
// Mining to have enough confirmations for the SVP fund transaction and updating the bridge.
515545
await rskUtils.mineAndSync(rskTxHelpers, 3);
516546
await rskUtils.waitAndUpdateBridge(rskTxHelper);
@@ -540,16 +570,23 @@ const execute = (description, newFederationConfig) => {
540570

541571
it('should register the SVP Spend transaction and finish the SVP process', async function () {
542572

573+
const latestBlockNumber2 = await rskTxHelper.getBlockNumber();
574+
console.log(`Latest block number before SVP Spend tx registration: ${latestBlockNumber2}`);
575+
543576
const blockNumberBeforeUpdateCollections = await rskTxHelper.getBlockNumber() - 3;
544577
const expectedCountOfSignatures = Math.floor(newFederationPublicKeys.length / 2) + 1;
545578

579+
// It's failing here because it's not finding the add_signature events.
546580
await waitForExpectedCountOfAddSignatureEventsToBeEmitted(rskTxHelpers, blockNumberBeforeUpdateCollections, expectedCountOfSignatures);
547581

548582
// Finding the SVP Spend transaction release_btc event
549583
const blockNumberAfterRelease = await rskTxHelper.getBlockNumber();
550584
const releaseBtcEvent = await rskUtils.findEventInBlock(rskTxHelper, PEGOUT_EVENTS.RELEASE_BTC.name, blockNumberBeforeUpdateCollections, blockNumberAfterRelease);
551585
svpSpendBtcTransaction = bitcoinJsLib.Transaction.fromHex(removePrefix0x(releaseBtcEvent.arguments.btcRawTransaction));
552586

587+
console.log(`SVP Spend transaction: `, svpSpendBtcTransaction);
588+
console.log(`SVP Spend transaction.toHex(): `, svpSpendBtcTransaction.toHex());
589+
553590
// Mining the SVP Spend transaction in bitcoin to register it in the Bridge
554591
await waitForBitcoinTxToBeInMempool(btcTxHelper, svpSpendBtcTransaction.getId());
555592
await btcTxHelper.mine(BTC_TO_RSK_MINIMUM_CONFIRMATIONS);
@@ -929,6 +966,7 @@ const execute = (description, newFederationConfig) => {
929966
const bridgeTransaction = await bridgeTxParser.getBridgeTransactionByTxHash(commitFederationTransactionReceipt.transactionHash);
930967

931968
commitFederationEvent = bridgeTransaction.events.find(event => event.name === 'commit_federation');
969+
console.log('commit_federation event:', commitFederationEvent);
932970
expect(commitFederationEvent, 'The commit federation event should be emitted.').to.not.be.null;
933971

934972
const expectedActivationHeight = bridgeTransaction.blockNumber + FEDERATION_ACTIVATION_AGE;
@@ -1013,6 +1051,7 @@ const assertOnlySvpFundTxHashUnsignedIsInStorage = async (rskTxHelper, pegoutBtc
10131051

10141052
const svpFundTxHashUnsignedRlpEncoded = await rskTxHelper.getClient().rsk.getStorageBytesAt(BRIDGE_ADDRESS, svpFundTxHashUnsignedStorageIndex);
10151053
const svpFundTxHashUnsigned = getBridgeStorageValueDecodedHexString(svpFundTxHashUnsignedRlpEncoded, false);
1054+
console.log('svpFundTxHashUnsigned: ', svpFundTxHashUnsigned);
10161055
expect(svpFundTxHashUnsigned).to.be.equal(pegoutBtcTxHash, 'The SVP fund tx hash unsigned storage value should be the tx id of the SVP fund tx.');
10171056

10181057
const svpFundTxSigned = await rskTxHelper.getClient().rsk.getStorageBytesAt(BRIDGE_ADDRESS, svpFundTxSignedStorageIndex);
@@ -1060,11 +1099,14 @@ const assertOnlySvpSpendTxValuesAreInStorage = async (rskTxHelper) => {
10601099
const svpSpendTxHashUnsigned = await rskTxHelper.getClient().rsk.getStorageBytesAt(BRIDGE_ADDRESS, svpSpendTxHashUnsignedStorageIndex);
10611100
expect(svpSpendTxHashUnsigned).to.not.be.equal('0x0', 'The SVP spend tx hash unsigned storage value should not be empty.');
10621101
const svpSpendTxHashUnsignedDecoded = decodeRlp(svpSpendTxHashUnsigned).toString('hex');
1102+
console.log('svpSpendTxHashUnsignedDecoded: ', svpSpendTxHashUnsignedDecoded);
10631103

10641104
const svpSpendTxWaitingForSignatures = await rskTxHelper.getClient().rsk.getStorageBytesAt(BRIDGE_ADDRESS, svpSpendTxWaitingForSignaturesStorageIndex);
10651105
expect(svpSpendTxWaitingForSignatures).to.not.be.equal('0x0', 'The SVP spend tx waiting for signatures storage value should not be empty.');
10661106

10671107
const decodedSvpSpendTxWaitingForSignatures = parseRLPToPegoutWaitingSignatures(svpSpendTxWaitingForSignatures)[0];
1108+
console.log('decodedSvpSpendTxWaitingForSignatures: ', decodedSvpSpendTxWaitingForSignatures);
1109+
console.log('decodedSvpSpendTxWaitingForSignatures.btcRawTx: ', decodedSvpSpendTxWaitingForSignatures.btcRawTxvpSpendTxWaitingForSignatures);
10681110
const svpSpendBtcTx = bitcoinJsLib.Transaction.fromHex(removePrefix0x(decodedSvpSpendTxWaitingForSignatures.btcRawTx));
10691111
expect(svpSpendTxHashUnsignedDecoded).to.be.equal(svpSpendBtcTx.getId(), 'The SVP spend tx hash unsigned storage value should be the tx id of the SVP spend tx.');
10701112

package-lock.json

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@rsksmart/btc-eth-unit-converter": "^1.0.0",
2020
"@rsksmart/btc-rsk-derivation": "^0.0.2",
2121
"@rsksmart/pmt-builder": "^3.0.0",
22-
"@rsksmart/powpeg-redeemscript-parser": "^1.0.1",
22+
"@rsksmart/powpeg-redeemscript-parser": "github:rsksmart/powpeg-redeemscript-parser#fbe3b981b3f768396833f5f832526a9751098089",
2323
"@rsksmart/rsk-precompiled-abis": "^6.0.0-ARROWHEAD",
2424
"@rsksmart/rsk-precompiled-abis-lovell": "git+https://github.com/rsksmart/precompiled-abis#7.0.0-LOVELL",
2525
"bn.js": "^4.11.8",

test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ global.Runners = {
9595
arrowhead600: createForkObject('arrowhead600', 1),
9696
arrowhead631: createForkObject('arrowhead631', 1),
9797
lovell700: createForkObject('lovell700', 1),
98+
tbd800: createForkObject('lovell700', 1200),
9899
},
99100
additionalFederationAddresses: []
100101
}

tests/01_01_00-activate-tbd800.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const activateForkTest = require('../lib/tests/activate-fork');
2+
3+
// Skipped activate-fork.js. When there is a new fork to be tested pre and post, unskip it in the activate-fork.js file
4+
activateForkTest.execute(
5+
Runners.common.forks.tbd800
6+
);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const federationChangeTests = require('../lib/tests/change-federation');
2+
3+
federationChangeTests.execute('Initial Federation change', Runners.config.federations.thirdFederation);

0 commit comments

Comments
 (0)