Skip to content

Commit

Permalink
lint(contracts): lint test
Browse files Browse the repository at this point in the history
  • Loading branch information
jdubpark committed Aug 23, 2024
1 parent cc47376 commit 4958408
Showing 1 changed file with 50 additions and 9 deletions.
59 changes: 50 additions & 9 deletions contracts/test/stake/IPTokenStaking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ contract IPTokenStakingTest is Test {
assertEq(ipTokenStaking.delegatorValidatorStakes(delegatorCmpPubkey, validatorCmpPubkey), 0 ether);

// Network shall not allow anyone to create a new validator on behalf if the sender account’s balance is 0.
bytes memory validator1Pubkey = hex"04e38d15ae6cc5d41cce27a2307903cb12a406cbf463fe5fef215bdf8aa988ced195e9327ac89cd362eaa0397f8d7f007c02b2a75642f174e455d339e4a1000000"; // pragma: allowlist-secret
bytes
memory validator1Pubkey = hex"04e38d15ae6cc5d41cce27a2307903cb12a406cbf463fe5fef215bdf8aa988ced195e9327ac89cd362eaa0397f8d7f007c02b2a75642f174e455d339e4a1000000"; // pragma: allowlist-secret
stakeAmount = 0 ether;
vm.deal(delegatorAddr, stakeAmount);
vm.prank(delegatorAddr);
Expand All @@ -203,7 +204,15 @@ contract IPTokenStakingTest is Test {
vm.deal(delegatorAddr, stakeAmount);
vm.prank(delegatorAddr);
vm.expectEmit(address(ipTokenStaking));
emit IIPTokenStaking.CreateValidator(delegatorUncmpPubkey, delegatorCmpPubkey, "delegator's validator", stakeAmount, 1000, 5000, 100);
emit IIPTokenStaking.CreateValidator(
delegatorUncmpPubkey,
delegatorCmpPubkey,
"delegator's validator",
stakeAmount,
1000,
5000,
100
);
ipTokenStaking.createValidator{ value: stakeAmount }({
validatorUncmpPubkey: delegatorUncmpPubkey,
moniker: "delegator's validator",
Expand All @@ -230,13 +239,22 @@ contract IPTokenStakingTest is Test {

// Network shall allow anyone to create a new validator on behalf of a validator.
// Note that the operation stakes sender’s tokens to the validator, and the delegator will still be the validator itself.
bytes memory validator2UncmpPubkey = hex"04e38d15ae6cc5d41cce27a2307903cb12a406cbf463fe5fef215bdf8aa988ced195e9327ac89cd362eaa0397f8d7f007c02b2a75642f174e455d339e4a1efe222"; // pragma: allowlist-secret
bytes
memory validator2UncmpPubkey = hex"04e38d15ae6cc5d41cce27a2307903cb12a406cbf463fe5fef215bdf8aa988ced195e9327ac89cd362eaa0397f8d7f007c02b2a75642f174e455d339e4a1efe222"; // pragma: allowlist-secret
bytes memory validator2CmpPubkey = Secp256k1.compressPublicKey(validator2UncmpPubkey);
stakeAmount = 1000 ether;
vm.deal(delegatorAddr, stakeAmount);
vm.prank(delegatorAddr);
vm.expectEmit(address(ipTokenStaking));
emit IIPTokenStaking.CreateValidator(validator2UncmpPubkey, validator2CmpPubkey, "validator", stakeAmount, 1000, 5000, 500);
emit IIPTokenStaking.CreateValidator(
validator2UncmpPubkey,
validator2CmpPubkey,
"validator",
stakeAmount,
1000,
5000,
500
);
ipTokenStaking.createValidatorOnBehalf{ value: stakeAmount }({ validatorUncmpPubkey: validator2UncmpPubkey });
// Check that stakes are correctly put on the validator
assertEq(ipTokenStaking.delegatorTotalStakes(validator2CmpPubkey), 1000 ether);
Expand Down Expand Up @@ -294,7 +312,15 @@ contract IPTokenStakingTest is Test {
// Create initially
vm.prank(delegatorAddr);
vm.expectEmit(address(ipTokenStaking));
emit IIPTokenStaking.CreateValidator(validatorUncmpPubkey, validatorCmpPubkey, "delegator's validator", stakeAmount, 1000, 5000, 100);
emit IIPTokenStaking.CreateValidator(
validatorUncmpPubkey,
validatorCmpPubkey,
"delegator's validator",
stakeAmount,
1000,
5000,
100
);
ipTokenStaking.createValidator{ value: stakeAmount }({
validatorUncmpPubkey: validatorUncmpPubkey,
moniker: "delegator's validator",
Expand All @@ -313,7 +339,15 @@ contract IPTokenStakingTest is Test {
// Create again
vm.prank(delegatorAddr);
vm.expectEmit(address(ipTokenStaking));
emit IIPTokenStaking.CreateValidator(validatorUncmpPubkey, validatorCmpPubkey, "delegator's validator", stakeAmount, 1000, 5000, 100);
emit IIPTokenStaking.CreateValidator(
validatorUncmpPubkey,
validatorCmpPubkey,
"delegator's validator",
stakeAmount,
1000,
5000,
100
);
ipTokenStaking.createValidator{ value: stakeAmount }({
validatorUncmpPubkey: validatorUncmpPubkey,
moniker: "bad name validator",
Expand Down Expand Up @@ -377,7 +411,8 @@ contract IPTokenStakingTest is Test {

// Network shall allow anyone to stake on behalf of another delegator.
validatorPubkey = delegatorCmpPubkey;
bytes memory delegator1UncmpPubkey = hex"04e38d15ae6cc5d41cce27a2307903cb12a406cbf463fe5fef215bdf8aa988ced195e9327ac89cd362eaa0397f8d7f007c02b2a75642f174e455d339e4a1000000"; // pragma: allowlist secret
bytes
memory delegator1UncmpPubkey = hex"04e38d15ae6cc5d41cce27a2307903cb12a406cbf463fe5fef215bdf8aa988ced195e9327ac89cd362eaa0397f8d7f007c02b2a75642f174e455d339e4a1000000"; // pragma: allowlist secret
bytes memory delegator1CmpPubkey = Secp256k1.compressPublicKey(delegator1UncmpPubkey);
stakeAmount = 1000 ether;
vm.deal(delegatorAddr, stakeAmount);
Expand Down Expand Up @@ -419,7 +454,10 @@ contract IPTokenStakingTest is Test {
vm.expectRevert("IPTokenStaking: Validator does not exist");
ipTokenStaking.stakeOnBehalf{ value: stakeAmount }(delegator1UncmpPubkey, validatorPubkey);

assertEq(ipTokenStaking.delegatorValidatorStakes(delegator1CmpPubkey, validatorPubkey), delegatorValidatorBefore);
assertEq(
ipTokenStaking.delegatorValidatorStakes(delegator1CmpPubkey, validatorPubkey),
delegatorValidatorBefore
);
assertEq(ipTokenStaking.delegatorTotalStakes(delegator1CmpPubkey), delegatorTotalBefore);
(isActive, moniker, totalStake, commissionRate, maxCommissionRate, maxCommissionChangeRate) = ipTokenStaking
.validatorMetadata(validatorPubkey);
Expand All @@ -442,7 +480,10 @@ contract IPTokenStakingTest is Test {
vm.expectRevert("IPTokenStaking: Stake amount too low");
ipTokenStaking.stakeOnBehalf{ value: stakeAmount }(delegator1UncmpPubkey, validatorPubkey);

assertEq(ipTokenStaking.delegatorValidatorStakes(delegator1CmpPubkey, validatorPubkey), delegatorValidatorBefore);
assertEq(
ipTokenStaking.delegatorValidatorStakes(delegator1CmpPubkey, validatorPubkey),
delegatorValidatorBefore
);
assertEq(ipTokenStaking.delegatorTotalStakes(delegator1CmpPubkey), delegatorTotalBefore);
(isActive, moniker, totalStake, commissionRate, maxCommissionRate, maxCommissionChangeRate) = ipTokenStaking
.validatorMetadata(validatorPubkey);
Expand Down

0 comments on commit 4958408

Please sign in to comment.