Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Add a test for issue183 #185

Merged
merged 5 commits into from
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions test/SubnetActorDiamond.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,43 @@ contract SubnetActorDiamondTest is Test {
saManager.join{value: amount}(DEFAULT_NET_ADDR, FvmAddress({addrType: 1, payload: new bytes(20)}));

require(saGetter.validatorCount() == 0);
require(gwGetter.listSubnets().length == 0);
}

function testSubnetActorDiamond_Join_Works_MultipleNewValidators() public {
_assertJoin(vm.addr(1234), DEFAULT_MIN_VALIDATOR_STAKE);
_assertJoin(vm.addr(1235), DEFAULT_MIN_VALIDATOR_STAKE);

require(saGetter.validatorCount() == 2);
require(gwGetter.listSubnets().length == 1);
}

function testSubnetActorDiamond_Join_Works_OneValidatorWithMinimumStake() public {
require(gwGetter.listSubnets().length == 0, "listSubnets correct");
require(saGetter.validatorCount() == 0, "validatorCount correct");

address validator = vm.addr(1234);

vm.startPrank(validator);
vm.deal(validator, DEFAULT_MIN_VALIDATOR_STAKE);

require(validator.balance == DEFAULT_MIN_VALIDATOR_STAKE, "balance() == DEFAULT_MIN_VALIDATOR_STAKE");
require(saGetter.stake(validator) == 0, "stake(validator) == 0");
require(saGetter.totalStake() == 0, "totalStake() == 0");

saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE}(
DEFAULT_NET_ADDR,
FvmAddress({addrType: 1, payload: new bytes(20)})
);

require(saGetter.stake(validator) == DEFAULT_MIN_VALIDATOR_STAKE);
require(saGetter.totalStake() == DEFAULT_MIN_VALIDATOR_STAKE);
require(validator.balance == 0);

vm.stopPrank();

require(saGetter.validatorCount() == 1, "validatorCount() correct");
require(gwGetter.listSubnets().length == 1, "listSubnets() correct");
}

function testSubnetActorDiamond_Join_Works_NoNewValidator_CollateralNotEnough() public {
Expand Down