From f5a859bfc8c3f990763c612089c89bddbc51b765 Mon Sep 17 00:00:00 2001 From: CedarMist <134699267+CedarMist@users.noreply.github.com> Date: Thu, 14 Mar 2024 12:12:28 +0000 Subject: [PATCH] contracts: added tests for multiple delegations --- contracts/contracts/tests/SubcallTests.sol | 9 ++++++++ contracts/test/subcall.ts | 24 ++++++++++++++++++++++ runtime/Cargo.lock | 6 +++--- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/contracts/contracts/tests/SubcallTests.sol b/contracts/contracts/tests/SubcallTests.sol index 98377142..a8f562f2 100644 --- a/contracts/contracts/tests/SubcallTests.sol +++ b/contracts/contracts/tests/SubcallTests.sol @@ -79,6 +79,15 @@ contract SubcallTests { Subcall.consensusDelegate(to, value); } + function testConsensusDelegateMulti(StakingAddress[] memory to, uint128 value) + external + payable + { + for( uint i = 0; i < to.length; i++ ) { + Subcall.consensusDelegate(to[i], uint128(value / to.length)); + } + } + event Result(bytes data); function testConsensusDelegateWithReceipt( diff --git a/contracts/test/subcall.ts b/contracts/test/subcall.ts index 03ee51ee..f663e8d8 100644 --- a/contracts/test/subcall.ts +++ b/contracts/test/subcall.ts @@ -125,6 +125,30 @@ describe('Subcall', () => { }; }); + /// Verifies that delegation to multiple validators at a time works (when no receipt is requested) + it('consensus.Delegate (multiple, without receipt)', async () => { + // Ensure contract has an initial balance. + const initialBalance = parseEther('1000'); + await ensureBalance(contract, initialBalance, owner); + + let randomPubkeys : Uint8Array[] = []; + for( let i = 0; i < 10; i++ ) { + const rawKp = await contract.generateRandomAddress(); + randomPubkeys.push(getBytes(rawKp.publicKey)); + } + + const tx = await contract.testConsensusDelegateMulti( + randomPubkeys, + parseEther('1000'), + ); + const receipt = await tx.wait(); + console.log('Receipt is', receipt); + + expect(await ethers.provider.getBalance(await contract.getAddress())).eq( + parseEther('0'), + ); + }); + it('Derive Staking Addresses', async () => { const newKeypair = await contract.generateRandomAddress(); diff --git a/runtime/Cargo.lock b/runtime/Cargo.lock index 2d9f1ae7..4be24fc2 100644 --- a/runtime/Cargo.lock +++ b/runtime/Cargo.lock @@ -2226,7 +2226,7 @@ dependencies = [ [[package]] name = "oasis-runtime-sdk" version = "0.8.4" -source = "git+https://github.com/oasisprotocol/oasis-sdk?branch=kostko/feature/messages-gas#2516bb0706953bf378f8abb1319861809a412b9c" +source = "git+https://github.com/oasisprotocol/oasis-sdk?branch=kostko/feature/messages-gas#04c38eb30f66197877768c27135b643211195743" dependencies = [ "anyhow", "base64", @@ -2265,7 +2265,7 @@ dependencies = [ [[package]] name = "oasis-runtime-sdk-evm" version = "0.5.0" -source = "git+https://github.com/oasisprotocol/oasis-sdk?branch=kostko/feature/messages-gas#2516bb0706953bf378f8abb1319861809a412b9c" +source = "git+https://github.com/oasisprotocol/oasis-sdk?branch=kostko/feature/messages-gas#04c38eb30f66197877768c27135b643211195743" dependencies = [ "anyhow", "base64", @@ -2297,7 +2297,7 @@ dependencies = [ [[package]] name = "oasis-runtime-sdk-macros" version = "0.3.0" -source = "git+https://github.com/oasisprotocol/oasis-sdk?branch=kostko/feature/messages-gas#2516bb0706953bf378f8abb1319861809a412b9c" +source = "git+https://github.com/oasisprotocol/oasis-sdk?branch=kostko/feature/messages-gas#04c38eb30f66197877768c27135b643211195743" dependencies = [ "darling 0.20.3", "proc-macro2 1.0.76",