|
| 1 | +pragma solidity ^0.8.26; |
| 2 | + |
| 3 | +import {Test, console} from "forge-std/Test.sol"; |
| 4 | +import {Vm} from "forge-std/Vm.sol"; |
| 5 | +import {BlueprintV7} from "../src/BlueprintV7.sol"; |
| 6 | +import {BlueprintCore} from "../src/BlueprintCore.sol"; |
| 7 | +import {Blueprint} from "../src/Blueprint.sol"; |
| 8 | +import {stdError} from "forge-std/StdError.sol"; |
| 9 | +import {MockERC20} from "./MockERC20.sol"; |
| 10 | + |
| 11 | +contract BlueprintTest is Test { |
| 12 | + BlueprintV7 public blueprint; |
| 13 | + MockERC20 public mockToken; |
| 14 | + bytes32 public projectId; |
| 15 | + address public workerAddress; |
| 16 | + address public dummyAddress; |
| 17 | + uint256 signerPrivateKey; |
| 18 | + |
| 19 | + function setUp() public { |
| 20 | + blueprint = new BlueprintV7(); |
| 21 | + blueprint.initialize(); // mimic upgradeable contract deploy behavior |
| 22 | + |
| 23 | + mockToken = new MockERC20(); |
| 24 | + |
| 25 | + // set crestal wallet address |
| 26 | + blueprint.setFeeCollectionWalletAddress(address(0x7D8be0Dd8915E3511fFDDABDD631812be824f578)); |
| 27 | + |
| 28 | + projectId = bytes32(0x2723a34e38d0f0aa09ce626f00aa23c0464b52c75516cf3203cc4c9afeaf2980); |
| 29 | + workerAddress = address(0x4d6585D89F889F29f77fd7Dd71864269BA1B31df); |
| 30 | + dummyAddress = address(0); |
| 31 | + signerPrivateKey = 0xA11CE; |
| 32 | + } |
| 33 | + |
| 34 | + function test_updateWorkerDeploymentConfig() public { |
| 35 | + string memory base64Proposal = "test base64 proposal"; |
| 36 | + string memory serverURL = "app.crestal.network"; |
| 37 | + |
| 38 | + // Add the payment address |
| 39 | + blueprint.addPaymentAddress(address(mockToken)); |
| 40 | + |
| 41 | + // set zero cost for create agents, use any number less than 0 |
| 42 | + blueprint.setCreateAgentTokenCost(address(mockToken), 0); |
| 43 | + |
| 44 | + // Create agent with token |
| 45 | + bytes32 requestId = |
| 46 | + blueprint.createAgentWithToken(projectId, base64Proposal, workerAddress, serverURL, address(mockToken)); |
| 47 | + |
| 48 | + // set zero cost for create agents, use any number less than 0 |
| 49 | + blueprint.setUpdateCreateAgentTokenCost(address(mockToken), 0); |
| 50 | + |
| 51 | + bytes32 updateHash = |
| 52 | + keccak256(abi.encodePacked(block.timestamp, address(this), requestId, base64Proposal, block.chainid)); |
| 53 | + // Expect the UpdateDeploymentConfig event |
| 54 | + vm.expectEmit(true, true, true, true); |
| 55 | + emit BlueprintCore.DeploymentConfigUpdate(projectId, requestId, workerAddress, updateHash, base64Proposal); |
| 56 | + |
| 57 | + // update agent deployment config |
| 58 | + blueprint.updateWorkerDeploymentConfig(address(mockToken), projectId, requestId, base64Proposal); |
| 59 | + } |
| 60 | +} |
0 commit comments