Skip to content

Commit

Permalink
better test profile
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Dec 24, 2024
1 parent d34a869 commit edb1b9d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 137 deletions.
44 changes: 0 additions & 44 deletions .gas-snapshot

This file was deleted.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,16 @@ forge script ./script/Deploy.s.sol:Upgrade<CONTRACT_NAME> \
Run tests on local network:
```sh
forge test
FOUNDRY_PROFILE=test forge test
# or -vvv to show reverts in detail
forge test -vvv
FOUNDRY_PROFILE=test forge test -vvv
```
or fork an existing chain and run the tests on it:

```sh
forge test --rpc-url <RPC_URL>
FOUNDRY_PROFILE=test forge test --rpc-url <RPC_URL>
```

### Code Coverage
Expand All @@ -218,7 +218,7 @@ forge coverage --no-match-coverage "(test|mock|script)"
You can examine the gas usage metrics using the command:

```sh
forge snapshot --snap ./test/.gas-snapshot
FOUNDRY_PROFILE=test forge snapshot --snap ./test/.gas-snapshot
```

You can see the snapshot `.gas-snapshot` file in the current directory.
Expand All @@ -234,7 +234,7 @@ forge fmt ./src/**/*.sol ./script/**/*.sol
If you have solhint installed, you can lint all contracts with:

```sh
solhint 'contracts/**/*.sol'
solhint 'src/**/*.sol' 'script/**/*.sol'
```

## Documentation
Expand Down
8 changes: 8 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ extra_output = ["storageLayout"]
# forces recompilation, required by Upgradable contracts
force = true

# testing does not care about the upgrade checks above
# so we disable them with
[profile.test]
ffi = false
ast = false
build_info = false
force = false

# fs permissions for deployment (false by default)
fs_permissions = [
{ access = "read", path = "out" },
Expand Down
43 changes: 43 additions & 0 deletions test/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
InvariantTest:invariant_AgentListingFee() (runs: 20, calls: 10000, reverts: 8948)
InvariantTest:invariant_ArtifactPriceRange() (runs: 20, calls: 10000, reverts: 8980)
InvariantTest:invariant_MaxArtifactCount() (runs: 20, calls: 10000, reverts: 8966)
InvariantTest:invariant_OwnerIsAnOperator() (runs: 20, calls: 10000, reverts: 8984)
SwanAgentTest:test_InBuyPhase() (gas: 4504233)
SwanAgentTest:test_InListingPhase() (gas: 4472223)
SwanAgentTest:test_RevertWhen_SetAmountPerRoundInBuyPhase() (gas: 4483818)
SwanAgentTest:test_RevertWhen_SetInvalidListingFee() (gas: 4492873)
SwanAgentTest:test_RevertWhen_SetListingFeeInListingPhase() (gas: 4473287)
SwanAgentTest:test_RevertWhen_WithdrawByAnotherOwner() (gas: 4504578)
SwanAgentTest:test_RevertWhen_WithdrawInBuyPhase() (gas: 4511219)
SwanAgentTest:test_SetListingFeeAndAmountPerRound() (gas: 4494303)
SwanAgentTest:test_WithdrawInWithdrawPhase() (gas: 4474466)
SwanFuzzTest:testFuzz_CalculateRoyalties(uint256,uint256,uint256) (runs: 100, μ: 4478299, ~: 4478418)
SwanFuzzTest:testFuzz_ChangeCycleTime(uint256,uint256,uint256,uint256,uint256,uint256) (runs: 100, μ: 6920710, ~: 6921521)
SwanFuzzTest:testFuzz_ListArtifact(string,string,bytes,uint256,string,string,uint96,uint256) (runs: 100, μ: 3924224, ~: 3924265)
SwanFuzzTest:testFuzz_TransferOwnership(address) (runs: 100, μ: 45365, ~: 45365)
SwanIntervalsTest:test_InBuyPhase() (gas: 4484295)
SwanIntervalsTest:test_InListingPhase() (gas: 4472682)
SwanIntervalsTest:test_InWithdrawPhase() (gas: 4487662)
SwanTest:test_CreateSwanAgents() (gas: 5664446)
SwanTest:test_PurchaseAnArtifact() (gas: 11299066)
SwanTest:test_RelistArtifact() (gas: 10252976)
SwanTest:test_RevertWhen_CreateAgentWithInvalidListingFee() (gas: 1620081)
SwanTest:test_RevertWhen_ListInWithdrawPhase() (gas: 5750299)
SwanTest:test_RevertWhen_ListMoreThanmaxArtifactCount() (gas: 10120467)
SwanTest:test_RevertWhen_PurchaseByAnotherAgent() (gas: 10143124)
SwanTest:test_RevertWhen_PurchaseInListingPhase() (gas: 10118022)
SwanTest:test_RevertWhen_PurchaseMoreThanAmountPerRound() (gas: 11334537)
SwanTest:test_RevertWhen_RelistAlreadyPurchasedArtifact() (gas: 11291065)
SwanTest:test_RevertWhen_RelistByAnotherSeller() (gas: 10128881)
SwanTest:test_RevertWhen_RelistInBuyPhase() (gas: 10164251)
SwanTest:test_RevertWhen_RelistInTheSameRound() (gas: 10121001)
SwanTest:test_RevertWhen_RelistInWithdrawPhase() (gas: 10163875)
SwanTest:test_RevertWhen_RelistMoreThanMaxArtifactCount() (gas: 13984570)
SwanTest:test_RevertWhen_SetMarketParametersWithInvalidFee() (gas: 1539839)
SwanTest:test_RevertWhen_UpgradeByNonOwner() (gas: 1543488)
SwanTest:test_SetAmountPerRound() (gas: 5721271)
SwanTest:test_SetFactories() (gas: 5172382)
SwanTest:test_SetMarketParameters() (gas: 5843929)
SwanTest:test_SetOracleParameters() (gas: 5666191)
SwanTest:test_TransferOwnership() (gas: 55434)
SwanTest:test_UpdateState() (gas: 12067589)
14 changes: 7 additions & 7 deletions test/Helper.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import {Upgrades} from "@openzeppelin/foundry-upgrades/Upgrades.sol";
import {UnsafeUpgrades} from "@openzeppelin/foundry-upgrades/Upgrades.sol";
import {Vm} from "forge-std/Vm.sol";
import {Test} from "forge-std/Test.sol";

Expand Down Expand Up @@ -132,17 +132,17 @@ abstract contract Helper is Test {
// deploy llm contracts
vm.startPrank(dria);

address registryProxy = Upgrades.deployUUPSProxy(
"LLMOracleRegistry.sol",
address registryProxy = UnsafeUpgrades.deployUUPSProxy(
address(new LLMOracleRegistry()),
abi.encodeCall(
LLMOracleRegistry.initialize,
(stakes.generatorStakeAmount, stakes.validatorStakeAmount, address(token), minRegistrationTime)
)
);
oracleRegistry = LLMOracleRegistry(registryProxy);

address coordinatorProxy = Upgrades.deployUUPSProxy(
"LLMOracleCoordinator.sol",
address coordinatorProxy = UnsafeUpgrades.deployUUPSProxy(
address(new LLMOracleCoordinator()),
abi.encodeCall(
LLMOracleCoordinator.initialize,
(
Expand All @@ -163,8 +163,8 @@ abstract contract Helper is Test {
artifactFactory = new SwanArtifactFactory();

// deploy swan
address swanProxy = Upgrades.deployUUPSProxy(
"Swan.sol",
address swanProxy = UnsafeUpgrades.deployUUPSProxy(
address(new Swan()),
abi.encodeCall(
Swan.initialize,
(
Expand Down
81 changes: 0 additions & 81 deletions test/script/Deploy.t.sol

This file was deleted.

0 comments on commit edb1b9d

Please sign in to comment.