Skip to content

Commit 1f1152e

Browse files
authored
Merge pull request #37 from KyberNetwork/add-test-script
feat: add simulation script
2 parents 4a73590 + 3da1426 commit 1f1152e

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

test/SimulateIntent.t.sol

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity 0.8.26;
3+
4+
// import {RevertReasonParser} from 'contracts/common/RevertReasonParser.sol';
5+
import 'forge-std/Test.sol';
6+
import 'forge-std/console.sol';
7+
import 'src/KSSmartIntentRouter.sol';
8+
9+
contract SimulateIntent is Test {
10+
// Test parameters
11+
string public RPC_URL;
12+
uint256 public BLOCK_NUMBER;
13+
address public SENDER;
14+
address public TARGET;
15+
bytes public CALL_DATA;
16+
uint256 public ETH_VALUE;
17+
18+
function setUp() public {
19+
// (Step 1) Load parameters
20+
RPC_URL = vm.envString('BSC_NODE_URL');
21+
BLOCK_NUMBER = 0;
22+
SENDER = 0x5ACf6f6E6c0a5B8595251416B50F6c7CF9508F7E;
23+
TARGET = 0xCa611DEb2914056D392bF77e13aCD544334dD957;
24+
ETH_VALUE = 0;
25+
CALL_DATA = hex'';
26+
27+
if (BLOCK_NUMBER != 0) {
28+
vm.createSelectFork(RPC_URL, BLOCK_NUMBER);
29+
} else {
30+
vm.createSelectFork(RPC_URL);
31+
}
32+
33+
// (Step 2) Set up transaction context
34+
deal(SENDER, ETH_VALUE);
35+
}
36+
37+
function testSimulateZapTransaction() public {
38+
uint256 currentBlock = block.number;
39+
40+
console.log('=== Simulation Setup ===');
41+
console.log('Block number:', currentBlock);
42+
console.log('Sender:', SENDER);
43+
console.log('Target:', TARGET);
44+
console.log('Calldata length:', CALL_DATA.length);
45+
console.log('ETH value:', ETH_VALUE);
46+
47+
vm.startPrank(SENDER);
48+
49+
// Execute the transaction with value and calldata
50+
(bool success, bytes memory returnData) = TARGET.call{value: ETH_VALUE}(CALL_DATA);
51+
52+
// Log transaction result
53+
if (success) {
54+
console.log('Transaction status: SUCCESS');
55+
if (returnData.length > 0) {
56+
console.log('Return data:');
57+
console.logBytes(returnData);
58+
} else {
59+
console.log('No return data');
60+
}
61+
} else {
62+
console.log('Transaction status: FAILED');
63+
}
64+
}
65+
66+
function excludeSig(bytes calldata data) public pure returns (bytes memory) {
67+
return data[4:];
68+
}
69+
}

0 commit comments

Comments
 (0)