Skip to content
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

01-04-54-post-iris-call-receive-headers / 01-04-55-post-iris-call-receive-header #26

Merged
merged 10 commits into from
Jan 8, 2024

Conversation

jpikora-iov
Copy link
Contributor

  • first part refactor of 01-04-54-post-iris-call-receive-headers 01_04_54-post_iris_call_receive_headers.js

@jpikora-iov jpikora-iov requested a review from a team as a code owner December 19, 2023 12:51
Copy link
Collaborator

@marcos-iov marcos-iov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good but if the plan is to run the same test 3 times we should encapsulate the logic in a single file to avoid repeating code everywhere. I can help you with this

@@ -1,7 +1,7 @@
{
"name": "rootstock-integration-tests",
"version": "1.0.0",
"lockfileVersion": 3,
"lockfileVersion": 2,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you are using node v18

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using node v20 now.

Copy link
Contributor

@jeremy-then jeremy-then left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of comments. Rebase with the latest changes on main. And run npm i with nodejs version 20.

const bridge = getBridge(rskTxHelper.getClient(), await getLatestActiveForkName());
const blockNumberInitial = await bridge.methods.getBtcBlockchainBestChainHeight().call();
const cowAddress = await rskTxHelper.newAccountWithSeed('cow');
const blockHash = await btcTxHelper.mine();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we have things like this in many places, but it's a bit confusing. Let's start fixing that.

The await btcTxHelper.mine(); call returns an array of btc block hashes, the ones that were mined. In this case, only one block was mined. But still, it returns an array. So let's called that blockHashes to make it clear.

const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider');
const { getBtcClient } = require('../lib/btc-client-provider');
const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util');
const { activateFork, sendTxWithCheck } = require('../lib/rsk-utils');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activateFork is not being used here.

@jeremy-then jeremy-then force-pushed the refactor/01-04-54-post-iris-call-receive-headers branch from ddacf09 to f325463 Compare January 3, 2024 05:53
@jpikora-iov
Copy link
Contributor Author

pipeline:run

@jeremy-then
Copy link
Contributor

pipeline:run

@jpikora-iov jpikora-iov changed the title WIP - 01-04-54-post-iris-call-receive-headers / 01-04-55-post-iris-call-receive-header 01-04-54-post-iris-call-receive-headers / 01-04-55-post-iris-call-receive-header Jan 3, 2024
jeremy-then
jeremy-then previously approved these changes Jan 3, 2024
Copy link
Contributor

@jeremy-then jeremy-then left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

}
});
});
twoWpTests.execute('Calling receiveHeaders after iris300', () => Runners.hosts.federate.host);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to leave a blank line at the end of each file, check the pther files also

@@ -1,47 +1,3 @@
const expect = require('chai').expect;
const twoWpTests = require('../lib/tests/post_iris_call_receive_headers');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const twoWpTests = require('../lib/tests/post_iris_call_receive_headers');
const receiveHeadersTests = require('../lib/tests/post_iris_call_receive_headers');

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the same on the remaining files

@@ -0,0 +1,3 @@
const twoWpTests = require('../lib/tests/post_iris_call_receive_headers');

twoWpTests.execute('Calling receiveHeaders after arrowhead600', () => Runners.hosts.federate.host);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
twoWpTests.execute('Calling receiveHeaders after arrowhead600', () => Runners.hosts.federate.host);
twoWpTests.execute('Calling receiveHeaders after last fork is active', () => Runners.hosts.federate.host);

If we put here after arrowhead then we'll need to update this every time a new rskj version is released

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the other files also

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the file naming seems a bit confusing. 03 prefix means that the latest fork is active, right? So no need to call each file last_fork_active.... And what's the logic for the numbers following 03_? Some are 01, 03, 50, etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess we are just following the line / list to keep the order of execution... @ed-iov ?

03_02_01-last_fork_active_powpeg_redeem_script.js
03_03_54-last_fork_active_call_receive_headers.js
03_03_55-last_fork_active_call_receive_header.js
04_00_01-key_control_initial_federation.js
04_00_02-fedchange.js
04_00_03-key_control_second_federation.js
04_00_04-2wp_after_fedchange.js
04_00_05-fastbridge_operation_with_rejection.js
04_00_06-fastbridge_after_fed_change.js
05_00_01-fee_per_kb.js
05_02_01-last_fork_active_powpeg_redeem_script.js
05_03_54-last_fork_active_call_receive_headers.js
05_03_55-last_fork_active_call_receive_header.js

the 54 / 55 comes from the original name. so i believe these can be skipped or replaced with 00...

const blockHeader = await btcTxHelper.getBlockHeader(blockHashes[0], false);
const blockchainInitialHeigth = await bridge.methods.getBtcBlockchainBestChainHeight().call();

await sendTxWithCheck(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put the method call and the callback in the own variables? It will make it easier to read

rskTxHelper,
bridge.methods.receiveHeader(ensure0x(blockHeader)),
cowAddress,
(result) => { expect(Number(result)).to.be.equal(0) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expected result 0 should also probably be in it's own constant. It will make it much clearer to understand

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');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this value, perhaps we could have a file with receive header response codes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would probably put just first 2 in the test file it's self...
why keep the rest if we don't use them?

const HEADER_RECEIVED = 0
const RECEIVE_HEADER_CALLED_TOO_SOON = -1;
const RECEIVE_HEADER_BLOCK_TOO_OLD = -2;
const RECEIVE_HEADER_CANT_FOUND_PREVIOUS_BLOCK = -3;
const RECEIVE_HEADER_BLOCK_PREVIOUSLY_SAVED = -4;
const RECEIVE_HEADER_UNEXPECTED_EXCEPTION = -99;

await activateFork(Runners.common.forks[forkName]);
};

const execute = (description, getRskHost) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not part of this ticket but I guess we should consider adding new test cases for the different error codes this method can return.

cc @ed-iov

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also all call updateBridge here as in receiveHeader test to make sure that the Bridge is up to date and that we a re informing a valid block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, it was in the original test for receiveHeader but not int the receiveHeaders one... @jeremy-then ??

Copy link
Contributor

@jeremy-then jeremy-then left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Contributor

@jeremy-then jeremy-then left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

jeremy-then
jeremy-then previously approved these changes Jan 5, 2024
Copy link
Contributor

@jeremy-then jeremy-then left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Collaborator

@marcos-iov marcos-iov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now, just a minor comment. I'm not sure about adding last_fork_active prefix to all files though, what's the purpose? I thought that the number prefix 03, 04, 05 already indicates that the last fork is active, right?

@@ -9,6 +9,9 @@ let rskTxHelper;
let btcTxHelper;
let bridge;

const HEADER_RECEIVED_OK = 0;
const RECEIVE_HEADER_CALLED_TOO_SOON = "-1";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why string?

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(RECEIVE_HEADER_CALLED_TOO_SOON);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(result).to.be.equal(RECEIVE_HEADER_CALLED_TOO_SOON);
expect(Number(result)).to.be.equal(RECEIVE_HEADER_CALLED_TOO_SOON);

That should do it

Copy link

sonarqubecloud bot commented Jan 5, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@marcos-iov
Copy link
Collaborator

pipeline:run

1 similar comment
@jpikora-iov
Copy link
Contributor Author

pipeline:run

Copy link
Contributor

@jeremy-then jeremy-then left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jeremy-then jeremy-then merged commit d9d7d3b into main Jan 8, 2024
4 checks passed
@jeremy-then jeremy-then deleted the refactor/01-04-54-post-iris-call-receive-headers branch January 8, 2024 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants