chore(security): enhance environment configuration, CI workflows, and wallet daemon with security improvements
- Restructure .env.example with security-focused documentation, service-specific environment file references, and AWS Secrets Manager integration - Update CLI tests workflow to single Python 3.13 version, add pytest-mock dependency, and consolidate test execution with coverage - Add comprehensive security validation to package publishing workflow with manual approval gates, secret scanning, and release
This commit is contained in:
40
contracts/test/fuzz/AIPowerRental.t.sol
Normal file
40
contracts/test/fuzz/AIPowerRental.t.sol
Normal file
@@ -0,0 +1,40 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import "forge-std/Test.sol";
|
||||
import "../../contracts/AIPowerRental.sol";
|
||||
|
||||
contract AIPowerRentalFuzzTest is Test {
|
||||
AIPowerRental public rental;
|
||||
address public owner;
|
||||
address public provider;
|
||||
address payable public renter;
|
||||
|
||||
function setUp() public {
|
||||
owner = address(this);
|
||||
provider = makeAddr("provider");
|
||||
renter = payable(makeAddr("renter"));
|
||||
rental = new AIPowerRental();
|
||||
}
|
||||
|
||||
function invariant_balanceInvariant() public {
|
||||
assertEq(address(rental).balance, 0, "Contract should hold no stray ETH");
|
||||
}
|
||||
|
||||
function testFuzz_RentalFlow(uint256 duration, uint256 price) public {
|
||||
vm.assume(duration > 0 && duration <= 365 days);
|
||||
vm.assume(price >= 0.001 ether && price <= 10 ether);
|
||||
|
||||
uint256 rentAmount = price * duration / 1 days;
|
||||
vm.deal(renter, rentAmount + 1 ether);
|
||||
|
||||
vm.prank(provider);
|
||||
rental.createRental(price, duration);
|
||||
|
||||
uint256 rentalId = 0;
|
||||
vm.prank(renter);
|
||||
rental.startRental{value: rentAmount}(rentalId);
|
||||
|
||||
assertEq(rental.getRentalEnd(rentalId), block.timestamp + duration);
|
||||
}
|
||||
}
|
||||
55
contracts/test/fuzz/DAOGovernor.t.sol
Normal file
55
contracts/test/fuzz/DAOGovernor.t.sol
Normal file
@@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import "forge-std/Test.sol";
|
||||
import "../../contracts/DAOGovernor.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
contract DAOGovernorFuzzTest is Test {
|
||||
DAOGovernor public governor;
|
||||
ERC20 public govToken;
|
||||
address public owner;
|
||||
address public proposer;
|
||||
address public voter;
|
||||
|
||||
function setUp() public {
|
||||
owner = address(this);
|
||||
proposer = makeAddr("proposer");
|
||||
voter = makeAddr("voter");
|
||||
govToken = new ERC20("GovToken", "GOV");
|
||||
governor = new DAOGovernor(address(govToken));
|
||||
|
||||
// Mint tokens and delegate
|
||||
vm.prank(owner);
|
||||
govToken.mint(voter, 1000e18);
|
||||
vm.prank(voter);
|
||||
govToken.delegate(voter);
|
||||
}
|
||||
|
||||
function invariant_quorumInvariant() public {
|
||||
uint256 quorum = governor.quorum();
|
||||
uint256 totalSupply = govToken.totalSupply();
|
||||
assertLe(quorum, totalSupply, "Quorum cannot exceed total supply");
|
||||
}
|
||||
|
||||
function testFuzz_ProposalFlow(uint256 amount, uint256 votes) public {
|
||||
vm.assume(amount >= 1e18 && amount <= 1000e18);
|
||||
vm.assume(votes >= 1e18 && votes <= 1000e18);
|
||||
|
||||
vm.prank(owner);
|
||||
govToken.mint(proposer, amount);
|
||||
vm.prank(proposer);
|
||||
govToken.delegate(proposer);
|
||||
|
||||
// Create proposal
|
||||
address[] memory targets = new address[](1);
|
||||
targets[0] = address(governor);
|
||||
uint256[] memory values = new uint256[](1);
|
||||
values[0] = 0;
|
||||
bytes[] memory calldatas = new bytes[](1);
|
||||
calldatas[0] = abi.encodeWithSignature("setQuorum(uint256)", 1000);
|
||||
|
||||
vm.prank(proposer);
|
||||
governor.propose(targets, values, calldatas, "Test proposal");
|
||||
}
|
||||
}
|
||||
38
contracts/test/fuzz/DynamicPricing.t.sol
Normal file
38
contracts/test/fuzz/DynamicPricing.t.sol
Normal file
@@ -0,0 +1,38 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import "forge-std/Test.sol";
|
||||
import "../../contracts/DynamicPricing.sol";
|
||||
|
||||
contract DynamicPricingFuzzTest is Test {
|
||||
DynamicPricing public pricing;
|
||||
address public owner;
|
||||
address public provider;
|
||||
|
||||
function setUp() public {
|
||||
owner = address(this);
|
||||
provider = makeAddr("provider");
|
||||
pricing = new DynamicPricing();
|
||||
vm.prank(owner);
|
||||
pricing.addProvider(provider);
|
||||
}
|
||||
|
||||
function invariant_noNegativePrice() public {
|
||||
uint256 price = pricing.getCurrentPrice(provider);
|
||||
assertGe(price, 0, "Price should never be negative");
|
||||
}
|
||||
|
||||
function testFuzz_PriceAdjustment(uint256 basePrice, uint256 utilization) public {
|
||||
vm.assume(basePrice >= 0.001 ether && basePrice <= 10 ether);
|
||||
vm.assume(utilization >= 0 && utilization <= 10000); // basis points
|
||||
|
||||
vm.prank(provider);
|
||||
pricing.setBasePrice(basePrice);
|
||||
|
||||
vm.prank(owner);
|
||||
pricing.updateUtilization(provider, utilization);
|
||||
|
||||
uint256 price = pricing.getCurrentPrice(provider);
|
||||
assertGe(price, 0, "Adjusted price must be non-negative");
|
||||
}
|
||||
}
|
||||
36
contracts/test/fuzz/EscrowService.t.sol
Normal file
36
contracts/test/fuzz/EscrowService.t.sol
Normal file
@@ -0,0 +1,36 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import "forge-std/Test.sol";
|
||||
import "../../contracts/EscrowService.sol";
|
||||
|
||||
contract EscrowServiceFuzzTest is Test {
|
||||
EscrowService public escrow;
|
||||
address public owner;
|
||||
address public provider;
|
||||
address payable public client;
|
||||
|
||||
function setUp() public {
|
||||
owner = address(this);
|
||||
provider = makeAddr("provider");
|
||||
client = payable(makeAddr("client"));
|
||||
escrow = new EscrowService();
|
||||
}
|
||||
|
||||
function invariant_balanceInvariant() public {
|
||||
assertEq(address(escrow).balance, 0, "Escrow should hold no stray ETH after operations");
|
||||
}
|
||||
|
||||
function testFuzz_EscrowFlow(uint256 amount) public {
|
||||
vm.assume(amount >= 0.01 ether && amount <= 100 ether);
|
||||
vm.deal(client, amount + 1 ether);
|
||||
|
||||
vm.prank(client);
|
||||
escrow.deposit{value: amount}(provider);
|
||||
assertEq(escrow.getBalance(provider), amount);
|
||||
|
||||
vm.prank(owner);
|
||||
escrow.release(provider, client);
|
||||
assertEq(escrow.getBalance(provider), 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user