Skip to content

Commit

Permalink
add single validator test
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Dec 26, 2024
1 parent f43b764 commit d5f87c5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down
43 changes: 21 additions & 22 deletions test/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
DeployTest:test_Deploy() (gas: 18809)
LLMOracleCoordinatorTest:test_RegisterOracles() (gas: 85623541)
LLMOracleCoordinatorTest:test_RevertWhen_ValidateWithoutWhitelist() (gas: 86163696)
LLMOracleCoordinatorTest:test_ValidatorIsGenerator() (gas: 86303124)
LLMOracleCoordinatorTest:test_WitValidation_NotEveryGeneratorGetFee() (gas: 86888424)
LLMOracleCoordinatorTest:test_WithValidation() (gas: 86721686)
LLMOracleCoordinatorTest:test_WithoutValidation() (gas: 86292219)
LLMOracleRegistryTest:test_RegisterGeneratorOracle() (gas: 19076281)
LLMOracleRegistryTest:test_RegisterValidatorOracle() (gas: 19181964)
LLMOracleRegistryTest:test_RemoveFromWhitelist() (gas: 19192586)
LLMOracleRegistryTest:test_RevertWhen_RegisterSameGeneratorTwice() (gas: 19079820)
LLMOracleRegistryTest:test_RevertWhen_RegistryHasNotApprovedByOracle() (gas: 18855997)
LLMOracleRegistryTest:test_RevertWhen_UnregisterBeforeEnoughTimeHasPassed() (gas: 19085782)
LLMOracleRegistryTest:test_RevertWhen_UnregisterSameGeneratorTwice() (gas: 19077356)
LLMOracleRegistryTest:test_UnregisterOracle() (gas: 19074421)
LLMOracleRegistryTest:test_WithdrawStakesAfterUnregistering() (gas: 19279660)
StatisticsTest:testFuzz_Average(uint8,uint8,uint8,uint8) (runs: 256, μ: 9748, ~: 9748)
StatisticsTest:testFuzz_StandardDeviation(uint8,uint8,uint8,uint8,uint8,uint8,uint8,uint8,uint8,uint8) (runs: 256, μ: 21895, ~: 21888)
StatisticsTest:testFuzz_Variance(uint8,uint8,uint8,uint8,uint8) (runs: 256, μ: 13902, ~: 13902)
StatisticsTest:test_Average() (gas: 135735)
StatisticsTest:test_StandardDeviation() (gas: 167111)
StatisticsTest:test_Variance() (gas: 163789)
LLMOracleCoordinatorTest:test_RegisterOracles() (gas: 11094589)
LLMOracleCoordinatorTest:test_RevertWhen_ValidateWithoutWhitelist() (gas: 11679788)
LLMOracleCoordinatorTest:test_ValidatorIsGenerator() (gas: 11829787)
LLMOracleCoordinatorTest:test_WitValidation_NotEveryGeneratorGetFee() (gas: 12479326)
LLMOracleCoordinatorTest:test_WithValidation() (gas: 12318783)
LLMOracleCoordinatorTest:test_WithoutValidation() (gas: 11849053)
LLMOracleRegistryTest:test_RegisterGeneratorOracle() (gas: 3726081)
LLMOracleRegistryTest:test_RegisterValidatorOracle() (gas: 3834643)
LLMOracleRegistryTest:test_RemoveFromWhitelist() (gas: 3846836)
LLMOracleRegistryTest:test_RevertWhen_RegisterSameGeneratorTwice() (gas: 3730771)
LLMOracleRegistryTest:test_RevertWhen_RegistryHasNotApprovedByOracle() (gas: 3452408)
LLMOracleRegistryTest:test_RevertWhen_UnregisterBeforeEnoughTimeHasPassed() (gas: 3739358)
LLMOracleRegistryTest:test_RevertWhen_UnregisterSameGeneratorTwice() (gas: 3733641)
LLMOracleRegistryTest:test_UnregisterOracle() (gas: 3729484)
LLMOracleRegistryTest:test_WithdrawStakesAfterUnregistering() (gas: 3955881)
StatisticsTest:testFuzz_Average(uint8,uint8,uint8,uint8) (runs: 256, μ: 7552, ~: 7552)
StatisticsTest:testFuzz_StandardDeviation(uint8,uint8,uint8,uint8,uint8,uint8,uint8,uint8,uint8,uint8) (runs: 256, μ: 26926, ~: 26920)
StatisticsTest:testFuzz_Variance(uint8,uint8,uint8,uint8,uint8) (runs: 256, μ: 14850, ~: 14850)
StatisticsTest:test_Average() (gas: 139247)
StatisticsTest:test_StandardDeviation() (gas: 198260)
StatisticsTest:test_Variance() (gas: 193562)
49 changes: 46 additions & 3 deletions test/LLMOracleCoordinator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.20;

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

import {LLMOracleTask, LLMOracleTaskParameters} from "../src/LLMOracleTask.sol";
import {LLMOracleRegistry, LLMOracleKind} from "../src/LLMOracleRegistry.sol";
Expand Down Expand Up @@ -259,7 +260,7 @@ contract LLMOracleCoordinatorTest is Helper {
assertEq(balanceAfter - balanceBefore, fees.platform);
}

/// @dev Oracle cannot validate if already participated as generator
/// @notice Oracle cannot validate if already participated as generator
/// @dev 1 generation + 1 validation
function test_ValidatorIsGenerator()
external
Expand Down Expand Up @@ -291,8 +292,8 @@ contract LLMOracleCoordinatorTest is Helper {
oracleCoordinator.validate(1, nonce, scores, metadata);
}

// @notice Request with 4 generation + 1 validation
// @dev Not every generator gets fee
/// @notice Request with 4 generation + 1 validation
/// @dev Not every generator gets fee
function test_WitValidation_NotEveryGeneratorGetFee()
external
fund
Expand Down Expand Up @@ -348,4 +349,46 @@ contract LLMOracleCoordinatorTest is Helper {
// only 1 generator doesn't get fee
assertEq(balanceAfter - balanceBefore, fees.platform + genFee);
}

/// @notice Request with 4 generation + 1 validation
/// @dev Not every generator gets fee
function test_WithSingleValidationAndGeneration()
external
fund
setOracleParameters(2, 1, 1)
deployment
registerOracles
safeRequest(requester, 1)
addValidatorsToWhitelist
{
uint256 balanceBefore = token.balanceOf(dria);

// get generator allowances before function execution & respond
uint256 generatorAllowancesBefore = token.allowance(address(oracleCoordinator), generators[0]);
console.log("BEFORE:", generatorAllowancesBefore);
safeRespond(generators[0], output, 1);

// validator validate with just one score
scores = [200];
safeValidate(validators[0], 1);

// check the task's status is Completed
(,,, LLMOracleTask.TaskStatus status, uint256 generatorFee,,,,) = oracleCoordinator.requests(1);
assertEq(uint8(status), uint8(LLMOracleTask.TaskStatus.Completed));

// check that fee is given
uint256 generatorAllowanceAfter = token.allowance(address(oracleCoordinator), generators[0]);
console.log("AFTER:", generatorAllowanceAfter);
assertEq(generatorAllowanceAfter - generatorAllowancesBefore, generatorFee);

// withdraw platform fees
vm.prank(dria);
oracleCoordinator.withdrawPlatformFees();

// get balance of dria after withdraw
uint256 balanceAfter = token.balanceOf(dria);

// should only have platform fee after withdrawing
assertEq(balanceAfter - balanceBefore, fees.platform);
}
}

0 comments on commit d5f87c5

Please sign in to comment.