@@ -96,7 +96,8 @@ contract AgentTest is Test {
9696 agent.createAgentWithToken (projectId, base64Proposal, workerAddress, serverURL, address (mockToken));
9797
9898 // set copy agent fee to 1000
99- uint256 copyAgentFee = 1000 ;
99+ uint256 copyAgentFee = 10 ; // 10 percent
100+ uint256 baseFee = 1000000 ; // 100000 token
100101
101102 // Expect revert because agentContract is not set in Blueprint
102103 // vm.expectRevert("Only Agent contract allow");
@@ -111,9 +112,12 @@ contract AgentTest is Test {
111112 );
112113
113114 // creator not set copy fee
114- vm.expectRevert ("Copy Agent is not set by the owner " );
115+ vm.expectRevert ("Platform fee is not set " );
115116 agent.createCopyAgentRequest (copyID, requestId, address (mockToken));
116117
118+ // set platform fee
119+ blueprint.setGlobalPlatformFee (baseFee, address (mockToken)); // 100000 token
120+
117121 // set copy agent fee
118122 vm.expectEmit (true , true , true , true );
119123 emit Agent.SetCopyAgentFee (requestId, address (this ), address (mockToken), copyAgentFee);
@@ -124,30 +128,34 @@ contract AgentTest is Test {
124128 agent.createCopyAgentRequest (copyID, requestId, address (mockToken));
125129
126130 // transfer some mock tokens to the sender
127- mockToken.mint (address (this ), copyAgentFee);
131+ uint256 totalFee = agent.getCreateCopyAgentFee (requestId, address (mockToken));
132+ mockToken.mint (address (this ), totalFee);
128133
129134 // revert: not grant allowance to Agent contract
130135 vm.expectRevert ("ERC20: transfer amount exceeds allowance " );
131136 agent.createCopyAgentRequest (copyID, requestId, address (mockToken));
132137
133138 // grant allowance to blueprint address
134- mockToken.approve (address (agent), copyAgentFee );
139+ mockToken.approve (address (agent), totalFee );
135140
136141 // owner cannot create copy agent request
137142 vm.expectRevert ("Cannot transfer to self address " );
138143 agent.createCopyAgentRequest (copyID, requestId, address (mockToken));
139144
140145 // transfer some mock tokens to relayer
141146 address relayer = address (0xBEEF );
142- mockToken.mint (relayer, copyAgentFee );
147+ mockToken.mint (relayer, totalFee );
143148 vm.prank (relayer);
144149
145150 // grant allowance to blueprint address
146- mockToken.approve (address (agent), copyAgentFee);
151+ mockToken.approve (address (agent), totalFee);
152+
153+ uint256 platformFee = blueprint.platformFee (address (mockToken));
154+ uint256 creatorFee = (copyAgentFee * platformFee) / blueprint.factor ();
147155
148156 // Expect the CopyAgentRequest event (from Agent, which emits the same event)
149157 vm.expectEmit (true , false , false , false );
150- emit Agent.CopyAgentRequest (copyID, requestId, address (this ));
158+ emit Agent.CopyAgentRequest (copyID, requestId, address (this ), platformFee + creatorFee );
151159
152160 // creator balance before creating copy agent request
153161 uint256 creatorBalanceBefore = mockToken.balanceOf (address (this ));
@@ -157,8 +165,6 @@ contract AgentTest is Test {
157165 agent.createCopyAgentRequest (copyID, requestId, address (mockToken));
158166
159167 // check fee collect wallet balance and creator balance
160- uint256 platformFee = (copyAgentFee * blueprint.platformCopyAgentFee ()) / blueprint.factor ();
161- uint256 creatorFee = copyAgentFee - platformFee;
162168 uint256 feeCollectionWalletBalance = mockToken.balanceOf (blueprint.feeCollectionWalletAddress ());
163169 // creator balance after creating copy agent request
164170 uint256 creatorBalanceAfter = mockToken.balanceOf (address (this ));
@@ -192,7 +198,7 @@ contract AgentTest is Test {
192198 projectId, base64Proposal, workerAddress, serverURL, address (mockToken), createAgentSig
193199 );
194200 // Set copy agent fee using gasless signature
195- uint256 copyAgentFee = 1000 ;
201+ uint256 copyAgentFee = 100 ; // 100 / 1000(factor) percent
196202 uint256 nonce = blueprint.getUserNonce (owner);
197203 bytes32 digest = blueprint.getSetCopyAgentFeeDigest (requestId, address (mockToken), copyAgentFee, nonce);
198204 (uint8 v , bytes32 r , bytes32 s ) = vm.sign (signerPrivateKey, digest);
@@ -215,7 +221,13 @@ contract AgentTest is Test {
215221 string memory serverURL = "app.crestal.network " ;
216222
217223 // Mint and approve tokens for owner (not relayer)
218- uint256 copyAgentFee = 1000 ;
224+ uint256 copyAgentFee = 100 ; // 100 / 1000 (factor) percent
225+
226+ uint256 baseFee = 1000000 ; // 100000 token
227+ uint256 totalFee = baseFee + (copyAgentFee * baseFee) / blueprint.factor ();
228+ // Set the global platform fee
229+ blueprint.setGlobalPlatformFee (baseFee, address (mockToken)); // 100000 token
230+
219231 // 0 cost, no need to set allowance and mint tokens
220232 // Create agent with token, owner is address(this)
221233 bytes32 requestId =
@@ -234,16 +246,16 @@ contract AgentTest is Test {
234246 bytes memory signature = abi.encodePacked (r, s, v);
235247
236248 // Mint and approve tokens for owner (not relayer)
237- mockToken.mint (user, copyAgentFee );
249+ mockToken.mint (user, totalFee );
238250 vm.prank (user);
239- mockToken.approve (address (agent), copyAgentFee );
251+ mockToken.approve (address (agent), totalFee );
240252
241253 // Record balances before
242254 uint256 ownerBalanceBefore = mockToken.balanceOf (user);
243255
244256 // Expect event
245- vm.expectEmit (true , true , true , true );
246- emit Agent.CopyAgentRequest (copyID, requestId, user);
257+ vm.expectEmit (true , true , true , false );
258+ emit Agent.CopyAgentRequest (copyID, requestId, user, 0 );
247259
248260 // Relayer submits the gasless request
249261 vm.prank (relayer);
@@ -252,6 +264,6 @@ contract AgentTest is Test {
252264 // Check relayer balance is unchanged (should be 0)
253265 assertEq (mockToken.balanceOf (relayer), 0 , "Relayer balance should be 0 after gasless copy agent request " );
254266 // Check owner's balance is reduced by the fee
255- assertEq (mockToken.balanceOf (user), ownerBalanceBefore - copyAgentFee , "Owner should pay the copy agent fee " );
267+ assertEq (mockToken.balanceOf (user), ownerBalanceBefore - totalFee , "Owner should pay the copy agent fee " );
256268 }
257269}
0 commit comments