-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: correcting forge tests #2
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,78 +175,6 @@ contract ServiceStakingMechUsages is BaseSetup { | |
super.setUp(); | ||
} | ||
|
||
/// @dev Test service staking with random number of executed tx-s (nonces) per day. | ||
/// @param numNonces Number of nonces per day. | ||
function testNonces(uint8 numNonces) external { | ||
// Send funds to a native token staking contract | ||
address(serviceStakingMechUsage).call{value: 100 ether}(""); | ||
|
||
// Stake services | ||
for (uint256 i = 0; i < numServices; ++i) { | ||
uint256 serviceId = i + 1; | ||
vm.startPrank(deployer); | ||
serviceRegistry.approve(address(serviceStakingMechUsage), serviceId); | ||
serviceStakingMechUsage.stake(serviceId); | ||
vm.stopPrank(); | ||
} | ||
|
||
// Get the Safe data payload | ||
payload = abi.encodeWithSelector(bytes4(keccak256("getThreshold()"))); | ||
// Number of days | ||
for (uint256 i = 0; i < numDays; ++i) { | ||
// Number of services | ||
for (uint256 j = 0; j < numServices; ++j) { | ||
uint256 serviceId = j + 1; | ||
ServiceRegistryL2.Service memory service = serviceRegistry.getService(serviceId); | ||
address payable multisig = payable(service.multisig); | ||
|
||
// Get the nonce before | ||
uint256 nonceBefore = GnosisSafe(multisig).nonce(); | ||
|
||
// Execute a specified number of nonces | ||
for (uint8 n = 0; n < numNonces; ++n) { | ||
// Get the signature | ||
bytes memory signature = new bytes(65); | ||
bytes memory bAddress = abi.encode(agentInstances[j]); | ||
for (uint256 b = 0; b < 32; ++b) { | ||
signature[b] = bAddress[b]; | ||
} | ||
for (uint256 b = 32; b < 64; ++b) { | ||
signature[b] = bytes1(0x00); | ||
} | ||
signature[64] = bytes1(0x01); | ||
|
||
vm.prank(agentInstances[j]); | ||
GnosisSafe(multisig).execTransaction(multisig, 0, payload, Enum.Operation.Call, 0, 0, 0, address(0), | ||
payable(address(0)), signature); | ||
} | ||
|
||
// Get the nonce after transactions | ||
uint256 nonceAfter = GnosisSafe(multisig).nonce(); | ||
assertGe(nonceAfter, nonceBefore); | ||
} | ||
|
||
// Move one day ahead | ||
vm.warp(block.timestamp + 1 days); | ||
|
||
// Call the checkpoint | ||
serviceStakingMechUsage.checkpoint(); | ||
|
||
// Unstake if there are no available rewards | ||
if (serviceStakingMechUsage.availableRewards() == 0) { | ||
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)) { | ||
vm.startPrank(deployer); | ||
serviceStakingMechUsage.unstake(serviceId); | ||
vm.stopPrank(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// @dev Test service staking with random number of executed tx-s (nonces) per day. | ||
/// @notice Service Id == 3 is inactive, i.e., doe not execute tx-s. | ||
/// @param numNonces Number of nonces per day. | ||
|
@@ -263,6 +191,9 @@ contract ServiceStakingMechUsages is BaseSetup { | |
vm.stopPrank(); | ||
} | ||
|
||
// Get the number of necessary requests (must be at most half of number of nonces) | ||
uint8 numRequests = numNonces / 2; | ||
|
||
// Get the Safe data payload | ||
payload = abi.encodeWithSelector(bytes4(keccak256("getThreshold()"))); | ||
// Number of days | ||
|
@@ -273,6 +204,11 @@ contract ServiceStakingMechUsages is BaseSetup { | |
ServiceRegistryL2.Service memory service = serviceRegistry.getService(serviceId); | ||
address payable multisig = payable(service.multisig); | ||
|
||
// Post a specified number of requests | ||
for (uint8 n = 0; n < numRequests; ++n) { | ||
agentMech.increaseRequestsCount(service.multisig); | ||
} | ||
|
||
// Get the nonce before | ||
uint256 nonceBefore = GnosisSafe(multisig).nonce(); | ||
|
||
|
@@ -391,79 +327,7 @@ contract ServiceStakingMechUsages is BaseSetup { | |
} | ||
} | ||
|
||
/// @dev Test service staking based on ERC20 token with random number of executed tx-s (nonces) per day. | ||
/// @param numNonces Number of nonces per day. | ||
function testNoncesToken(uint8 numNonces) external { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a repeating test. |
||
// Send tokens to a ERC20 token staking contract | ||
token.approve(address(serviceStakingTokenMechUsage), 100 ether); | ||
serviceStakingTokenMechUsage.deposit(100 ether); | ||
|
||
// Stake services | ||
for (uint256 i = 0; i < numServices; ++i) { | ||
uint256 serviceId = i + numServices + 1; | ||
vm.startPrank(deployer); | ||
serviceRegistry.approve(address(serviceStakingTokenMechUsage), serviceId); | ||
serviceStakingTokenMechUsage.stake(serviceId); | ||
vm.stopPrank(); | ||
} | ||
|
||
// Get the Safe data payload | ||
payload = abi.encodeWithSelector(bytes4(keccak256("getThreshold()"))); | ||
// Number of days | ||
for (uint256 i = 0; i < numDays; ++i) { | ||
// Number of services | ||
for (uint256 j = 0; j < numServices; ++j) { | ||
uint256 serviceId = j + numServices + 1; | ||
ServiceRegistryL2.Service memory service = serviceRegistry.getService(serviceId); | ||
address payable multisig = payable(service.multisig); | ||
|
||
// Get the nonce before | ||
uint256 nonceBefore = GnosisSafe(multisig).nonce(); | ||
|
||
// Execute a specified number of nonces | ||
for (uint8 n = 0; n < numNonces; ++n) { | ||
// Get the signature | ||
bytes memory signature = new bytes(65); | ||
bytes memory bAddress = abi.encode(agentInstances[j + numServices]); | ||
for (uint256 b = 0; b < 32; ++b) { | ||
signature[b] = bAddress[b]; | ||
} | ||
for (uint256 b = 32; b < 64; ++b) { | ||
signature[b] = bytes1(0x00); | ||
} | ||
signature[64] = bytes1(0x01); | ||
vm.prank(agentInstances[j + numServices]); | ||
GnosisSafe(multisig).execTransaction(multisig, 0, payload, Enum.Operation.Call, 0, 0, 0, address(0), | ||
payable(address(0)), signature); | ||
} | ||
|
||
// Get the nonce after transactions | ||
uint256 nonceAfter = GnosisSafe(multisig).nonce(); | ||
assertGe(nonceAfter, nonceBefore); | ||
} | ||
|
||
// Move one day ahead | ||
vm.warp(block.timestamp + 1 days); | ||
|
||
// Call the checkpoint | ||
serviceStakingTokenMechUsage.checkpoint(); | ||
|
||
// Unstake if there are no available rewards | ||
if (serviceStakingTokenMechUsage.availableRewards() == 0) { | ||
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)) { | ||
vm.startPrank(deployer); | ||
serviceStakingTokenMechUsage.unstake(serviceId); | ||
vm.stopPrank(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// @dev Test service staking with random number of executed tx-s (nonces) per day with AI agent mech. | ||
/// @dev Test service staking with random number of executed tx-s (nonces) per day with all services being staked. | ||
/// @param numNonces Number of nonces per day. | ||
function testNoncesAgentMech(uint8 numNonces) external { | ||
// Send funds to a native token staking contract | ||
|
@@ -543,7 +407,7 @@ contract ServiceStakingMechUsages is BaseSetup { | |
} | ||
} | ||
|
||
/// @dev Test service staking based on ERC20 token with random number of executed tx-s (nonces) per day with AI agent mech. | ||
/// @dev Test service staking based on ERC20 token with random number of executed tx-s (nonces) per day with all services being staked. | ||
/// @param numNonces Number of nonces per day. | ||
function testNoncesTokenAgentMech(uint8 numNonces) external { | ||
// Send tokens to a ERC20 token staking contract | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a repeating test.