-
Notifications
You must be signed in to change notification settings - Fork 6
Add union bridge methods integration tests #288
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
base: main
Are you sure you want to change the base?
Conversation
- Add `deployUnionBridgeContract` to contract deployer util - Add `getBridgeStorageIndexFromLongKey` helper function.
e608a1f to
6a56680
Compare
|
|
|
||
| const UNION_BRIDGE_ADDRESS = '0x5988645D30cD01E4B3bC2c02CB3909dEC991Ae31'; | ||
|
|
||
| // 400 RBTC initial locking cap |
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.
| // 400 RBTC initial locking cap | |
| // 500 RBTC initial locking cap |
?
lib/tests/union-bridge-methods.js
Outdated
| const {BRIDGE_ADDRESS} = require("../constants/bridge-constants"); | ||
| const {getBridgeStorageValueDecodedHexString, removePrefix0x} = require("../utils"); | ||
|
|
||
|
|
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.
nit: Too many empty lines.
lib/tests/union-bridge-methods.js
Outdated
|
|
||
| const {btcToWeis, ethToWeis, weisToEth} = require("@rsksmart/btc-eth-unit-converter"); | ||
|
|
||
| const {CHANGE_LOCKING_CAP_AUTHORIZERS_PKS, CHANGE_UNION_BRIDGE_CONTRACT_ADDRESS_AUTHORIZER_PK, |
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.
nit: can we format it like?:
const {
CHANGE_LOCKING_CAP_AUTHORIZERS_PKS,
CHANGE_UNION_BRIDGE_CONTRACT_ADDRESS_AUTHORIZER_PK,
CHANGE_TRANSFER_PERMISSIONS_AUTHORIZERS_PKS,
UNION_RESPONSE_CODES,
UNION_BRIDGE_ADDRESS,
UNION_BRIDGE_STORAGE_INDICES,
INITIAL_LOCKING_CAP,
LOCKING_CAP_INCREMENTS_MULTIPLIER,
UNION_BRIDGE_EVENTS,
} = require("../constants/union-bridge-constants");
| const RELEASE_PERMISSION_ENABLED = true; | ||
| const RELEASE_PERMISSION_DISABLED = false; | ||
|
|
||
| let rskTxHelpers; |
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.
No big deal, but let's put all these variables inside execute.
| await deployAndFundUnionBridgeContract(); | ||
| }); | ||
|
|
||
| it('should setUnionBridgeContractAddressForTestnet change union address when calling on regtest', async () => { |
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.
| it('should setUnionBridgeContractAddressForTestnet change union address when calling on regtest', async () => { | |
| it('should change union address when calling setUnionBridgeContractAddressForTestnet on regtest', async () => { |
What do you think?
| await assertNoEventWasEmitted(txReceipt); | ||
| }); | ||
|
|
||
| it('should increaseUnionBridgeLockingCap fail and return UNAUTHORIZED_CALLER when calling from an unauthorized address', async () => { |
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.
| it('should increaseUnionBridgeLockingCap fail and return UNAUTHORIZED_CALLER when calling from an unauthorized address', async () => { | |
| it('should fail and return UNAUTHORIZED_CALLER when calling increaseUnionBridgeLockingCap from an unauthorized address', async () => { |
What do you think?
lib/tests/union-bridge-methods.js
Outdated
| await assertNoEventWasEmitted(txReceipt); | ||
| }); | ||
|
|
||
| it('should increaseUnionBridgeLockingCap first vote be successful when caller address is authorized', async () => { |
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.
| it('should increaseUnionBridgeLockingCap first vote be successful when caller address is authorized', async () => { | |
| it('should successfully register a first vote while calling increaseUnionBridgeLockingCap when the caller address is authorized', async () => { |
lib/tests/union-bridge-methods.js
Outdated
| await assertNoEventWasEmitted(txReceipt); | ||
| }); | ||
|
|
||
| it('should increaseUnionBridgeLockingCap second vote, to a different value than first vote, be successful when caller address is authorizer2', async () => { |
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.
| it('should increaseUnionBridgeLockingCap second vote, to a different value than first vote, be successful when caller address is authorizer2', async () => { | |
| it('should successfully register a second vote with a different value than the first vote while calling increaseUnionBridgeLockingCap with authorizer2 address', async () => { |
lib/tests/union-bridge-methods.js
Outdated
| await assertNoEventWasEmitted(txReceipt); | ||
| }); | ||
|
|
||
| it('should increaseUnionBridgeLockingCap third vote for same first vote value be successful when authorizer_2 vote again', async () => { |
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.
| it('should increaseUnionBridgeLockingCap third vote for same first vote value be successful when authorizer_2 vote again', async () => { | |
| it('should successfully register a third vote for same first vote value while calling increaseUnionBridgeLockingCap when authorizer2 votes again', async () => { |
lib/tests/union-bridge-methods.js
Outdated
| await assertLogUnionLockingCapIncreased(txReceipt, changeLockingCapAuthorizer2Address, INITIAL_LOCKING_CAP, NEW_LOCKING_CAP_1); | ||
| }); | ||
|
|
||
| it("should increaseUnionBridgeLockingCap(first vote after previous election ended) be successful when authorizer_2 vote again for previous second value value", async () => { |
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.
Same description refactors as the others?
| await assertNoEventWasEmitted(txReceipt); | ||
| }); | ||
|
|
||
| it("should increaseUnionBridgeLockingCap return INVALID_VALUE when trying to decrease the locking cap", async () => { |
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.
Same description refactors as the others?
| await assertNoEventWasEmitted(txReceipt); | ||
| }); | ||
|
|
||
| it("should requestUnionBridgeRbtc return UNAUTHORIZED_CALLER when caller is unauthorized", async () => { |
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.
Same description refactors as the others?
| await assertNoEventWasEmitted(txReceipt); | ||
| }); | ||
|
|
||
| it("should requestUnionRbtc be successful when called from union bridge contract address", async () => { |
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.
Same description refactors as the others?
| await assertWeisTransferredToUnionBridgeBalance(expectedWeisTransferred); | ||
| }); | ||
|
|
||
| it("should releaseUnionBridgeRbtc return UNAUTHORIZED_CALLER when caller is unauthorized", async () => { |
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.
Same description refactors as the others?
| await assertNoEventWasEmitted(txReceipt); | ||
| }); | ||
|
|
||
| it("should releaseUnionBridgeRbtc be successful when called from union bridge contract", async () => { |
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.
Same description refactors as the others?
| await assertUnionBridgeBalance(expectedUnionBridgeBalanceAfter); | ||
| }); | ||
|
|
||
| it("should setUnionBridgeTransferPermissions return UNAUTHORIZED_CALLER when caller is unauthorized", async () => { |
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.
Same description refactors as the others?
lib/tests/union-bridge-methods.js
Outdated
| await assertNoEventWasEmitted(txReceipt); | ||
| }); | ||
|
|
||
| it("should setUnionBridgeTransferPermissions first vote be successful when called from authorized caller", async () => { |
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.
Same description refactors as the others?
lib/tests/union-bridge-methods.js
Outdated
| await assertNoEventWasEmitted(txReceipt); | ||
| }); | ||
|
|
||
| it("should setUnionBridgeTransferPermissions second vote for different value be successful when called from authorized caller", async () => { |
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.
Same description refactors as the others?
| }); | ||
| } | ||
|
|
||
| const importAccounts = async (privateKeys) => { |
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.
I know there's a importAccounts function in change-federation.js. I think it's time for this function to be put into an util module and reuse it.
| .padStart(66, '0x'); | ||
| }; | ||
|
|
||
| const getBridgeStorageIndexFromLongKey = (storageKey) => { |
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.
Should this be in an utils file? Like 2wp-utils.js or something like that.
|
|
||
| chai.use(require('chai-as-promised')); | ||
|
|
||
| const {CHANGE_LOCKING_CAP_AUTHORIZERS_PKS, CHANGE_UNION_BRIDGE_CONTRACT_ADDRESS_AUTHORIZER_PK, |
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.
Format this as my format suggestion above?
| const REQUEST_PERMISSION_ENABLED = true; | ||
| const RELEASE_PERMISSION_ENABLED = true; | ||
|
|
||
| let rskTxHelpers; |
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.
All these variables inside execute? Check change-federation.js as an example.
| }); | ||
| } | ||
|
|
||
| const importAccounts = async (rskTxHelper, privateKeys) => { |
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.
Same as the one in the other file? Time to move these importAccounts functions to a utils file to reuse them.
|



This pull request introduces ITs for the Union Bridge methods.
Integration tests:
tests/01_00_00-calls-union-bridge-methods-fail.js)tests/01_01_01-union-bridge-methods.js)Union Bridge Contract and Deployment:
UnionBridgeContractSolidity contract, which acts as a wrapper over the bridge contract to request and release RBTC, and includes fallback and receive functions. (contracts/UnionBridgeContract.sol)UnionBridgeContract, including a newdeployUnionBridgeContractfunction. (lib/contractDeployer.js) [1] [2]Constants and Utilities:
lib/constants/union-bridge-constants.js)getBridgeStorageIndexFromLongKeyfor generating storage indices using keccak256. (lib/utils.js) [1] [2] [3]Dependency Updates:
package.json)rskj:union_bridge_integrationfed:union_bridge_integration