Skip to content

Commit

Permalink
contracts: added tests for multiple delegations
Browse files Browse the repository at this point in the history
  • Loading branch information
CedarMist committed Mar 14, 2024
1 parent 030a16b commit f5a859b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
9 changes: 9 additions & 0 deletions contracts/contracts/tests/SubcallTests.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
24 changes: 24 additions & 0 deletions contracts/test/subcall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions runtime/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f5a859b

Please sign in to comment.