diff --git a/lib/autonolas-registries b/lib/autonolas-registries index f68ab3c..2ce07e8 160000 --- a/lib/autonolas-registries +++ b/lib/autonolas-registries @@ -1 +1 @@ -Subproject commit f68ab3c2025721dda66aca778bda4ca44ca69193 +Subproject commit 2ce07e89e070230675727cf9c91d223d5f8e8ada diff --git a/lib/forge-std b/lib/forge-std index 267acd3..2f11269 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 267acd30a625086b3f16e1a28cfe0c5097fa46b8 +Subproject commit 2f112697506eab12d433a65fdc31a639548fe365 diff --git a/test/ServiceStakingMechUsage.js b/test/ServiceStakingMechUsage.js index f87a569..b4b5182 100644 --- a/test/ServiceStakingMechUsage.js +++ b/test/ServiceStakingMechUsage.js @@ -38,6 +38,7 @@ describe("ServiceStakingMechUsage", function () { maxNumServices: 10, rewardsPerSecond: "1" + "0".repeat(15), minStakingDeposit: 10, + maxNumInactivityPeriods: 3, livenessPeriod: livenessPeriod, // Ten seconds livenessRatio: "1" + "0".repeat(16), // 0.01 transaction per second (TPS) numAgentInstances: 1, @@ -45,6 +46,7 @@ describe("ServiceStakingMechUsage", function () { threshold: 0, configHash: bytes32Zero }; + const maxInactivity = serviceParams.maxNumInactivityPeriods * livenessPeriod + 1; beforeEach(async function () { signers = await ethers.getSigners(); @@ -173,15 +175,15 @@ describe("ServiceStakingMechUsage", function () { await serviceStakingMechUsage.stake(serviceId); // Check that the service is staked - const isStaked = await serviceStakingMechUsage.isServiceStaked(serviceId); - expect(isStaked).to.equal(true); + const stakingState = await serviceStakingMechUsage.getServiceStakingState(serviceId); + expect(stakingState).to.equal(1); // Get the service multisig contract const service = await serviceRegistry.getService(serviceId); const multisig = await ethers.getContractAt("GnosisSafe", service.multisig); // Increase the time while the service does not reach the required amount of transactions per second (TPS) - await helpers.time.increase(livenessPeriod); + await helpers.time.increase(maxInactivity); // Calculate service staking reward that must be zero const reward = await serviceStakingMechUsage.calculateServiceStakingReward(serviceId); @@ -217,8 +219,8 @@ describe("ServiceStakingMechUsage", function () { await serviceStakingMechUsage.stake(serviceId); // Check that the service is staked - const isStaked = await serviceStakingMechUsage.isServiceStaked(serviceId); - expect(isStaked).to.equal(true); + const stakingState = await serviceStakingMechUsage.getServiceStakingState(serviceId); + expect(stakingState).to.equal(1); // Get the service multisig contract const service = await serviceRegistry.getService(serviceId); @@ -228,7 +230,7 @@ describe("ServiceStakingMechUsage", function () { await agentMech.increaseRequestsCount(service.multisig); // Increase the time while the service does not reach the required amount of transactions per second (TPS) - await helpers.time.increase(livenessPeriod); + await helpers.time.increase(maxInactivity); // Calculate service staking reward that must be zero const reward = await serviceStakingMechUsage.calculateServiceStakingReward(serviceId); @@ -280,7 +282,7 @@ describe("ServiceStakingMechUsage", function () { await safeContracts.executeTx(multisig, txHashData, [signMessageData], 0); // Increase the time for the liveness period - await helpers.time.increase(livenessPeriod); + await helpers.time.increase(maxInactivity); // Call the checkpoint at this time await serviceStakingMechUsage.checkpoint(); @@ -292,7 +294,7 @@ describe("ServiceStakingMechUsage", function () { await safeContracts.executeTx(multisig, txHashData, [signMessageData], 0); // Increase the time for the liveness period - await helpers.time.increase(livenessPeriod); + await helpers.time.increase(maxInactivity); // Calculate service staking reward that must be greater than zero const reward = await serviceStakingMechUsage.calculateServiceStakingReward(serviceId); @@ -373,7 +375,7 @@ describe("ServiceStakingMechUsage", function () { await safeContracts.executeTx(multisig, txHashData, [signMessageData], 0); // Increase the time for the liveness period - await helpers.time.increase(livenessPeriod); + await helpers.time.increase(maxInactivity); // Calculate service staking reward that must be greater than zero const reward = await serviceStakingTokenMechUsage.calculateServiceStakingReward(sId); diff --git a/test/ServiceStakingMechUsages.t.sol b/test/ServiceStakingMechUsages.t.sol index 3b7df2a..404790a 100644 --- a/test/ServiceStakingMechUsages.t.sol +++ b/test/ServiceStakingMechUsages.t.sol @@ -59,6 +59,8 @@ contract BaseSetup is Test { uint256 internal rewardsPerSecond = 0.0001 ether; // Minimum service staking deposit value required for staking uint256 internal minStakingDeposit = regDeposit; + // Max number of accumulated inactivity periods after which the service is evicted + uint256 internal maxNumInactivityPeriods = 3; // Liveness period uint256 internal livenessPeriod = 1 days; // Liveness ratio in the format of 1e18 @@ -107,7 +109,8 @@ contract BaseSetup is Test { // Deploy service staking native token and arbitrary ERC20 token ServiceStakingBase.StakingParams memory stakingParams = ServiceStakingBase.StakingParams(maxNumServices, - rewardsPerSecond, minStakingDeposit, livenessPeriod, livenessRatio, numAgentInstances, emptyArray, 0, bytes32(0)); + rewardsPerSecond, minStakingDeposit, maxNumInactivityPeriods, livenessPeriod, livenessRatio, + numAgentInstances, emptyArray, 0, bytes32(0)); agentMech = new MockAgentMech(); serviceStakingMechUsage = new ServiceStakingMechUsage(stakingParams, address(serviceRegistry), multisigProxyHash, address(agentMech)); @@ -236,7 +239,7 @@ contract ServiceStakingMechUsages is BaseSetup { } // Move one day ahead - vm.warp(block.timestamp + 1 days); + vm.warp(block.timestamp + serviceStakingMechUsage.maxAllowedInactivity() + 1); // Call the checkpoint serviceStakingMechUsage.checkpoint(); @@ -246,7 +249,7 @@ contract ServiceStakingMechUsages is BaseSetup { for (uint256 j = 0; j < numServices; ++j) { uint256 serviceId = j + 1; // Unstake if the service is not yet unstaked, otherwise ignore - if (!serviceStakingMechUsage.isServiceStaked(serviceId)) { + if (uint8(serviceStakingMechUsage.getServiceStakingState(serviceId)) > 0) { vm.startPrank(deployer); serviceStakingMechUsage.unstake(serviceId); vm.stopPrank(); @@ -307,7 +310,7 @@ contract ServiceStakingMechUsages is BaseSetup { } // Move one day ahead - vm.warp(block.timestamp + 1 days); + vm.warp(block.timestamp + serviceStakingMechUsage.maxAllowedInactivity() + 1); // Call the checkpoint serviceStakingMechUsage.checkpoint(); @@ -317,7 +320,7 @@ contract ServiceStakingMechUsages is BaseSetup { for (uint256 j = 0; j < numServices; ++j) { uint256 serviceId = j + 1; // Unstake if the service is not yet unstaked, otherwise ignore - if (!serviceStakingMechUsage.isServiceStaked(serviceId)) { + if (uint8(serviceStakingMechUsage.getServiceStakingState(serviceId)) > 0) { vm.startPrank(deployer); serviceStakingMechUsage.unstake(serviceId); vm.stopPrank(); @@ -387,7 +390,7 @@ contract ServiceStakingMechUsages is BaseSetup { } // Move one day ahead - vm.warp(block.timestamp + 1 days); + vm.warp(block.timestamp + serviceStakingMechUsage.maxAllowedInactivity() + 1); // Call the checkpoint serviceStakingMechUsage.checkpoint(); @@ -397,7 +400,7 @@ contract ServiceStakingMechUsages is BaseSetup { for (uint256 j = 0; j < numServices; ++j) { uint256 serviceId = j + 1; // Unstake if the service is not yet unstaked, otherwise ignore - if (!serviceStakingMechUsage.isServiceStaked(serviceId)) { + if (uint8(serviceStakingMechUsage.getServiceStakingState(serviceId)) > 0) { vm.startPrank(deployer); serviceStakingMechUsage.unstake(serviceId); vm.stopPrank(); @@ -467,7 +470,7 @@ contract ServiceStakingMechUsages is BaseSetup { } // Move one day ahead - vm.warp(block.timestamp + 1 days); + vm.warp(block.timestamp + serviceStakingMechUsage.maxAllowedInactivity() + 1); // Call the checkpoint serviceStakingTokenMechUsage.checkpoint(); @@ -477,7 +480,7 @@ contract ServiceStakingMechUsages is BaseSetup { for (uint256 j = 0; j < numServices; ++j) { uint256 serviceId = j + numServices + 1; // Unstake if the service is not yet unstaked, otherwise ignore - if (!serviceStakingTokenMechUsage.isServiceStaked(serviceId)) { + if (uint8(serviceStakingTokenMechUsage.getServiceStakingState(serviceId)) > 0) { vm.startPrank(deployer); serviceStakingTokenMechUsage.unstake(serviceId); vm.stopPrank();