forked from yug49/PyPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-contract-connection.js
More file actions
180 lines (165 loc) · 6.58 KB
/
test-contract-connection.js
File metadata and controls
180 lines (165 loc) · 6.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
const { createPublicClient, http } = require("viem");
const { worldchainSepolia } = require("viem/chains");
async function testContractConnection() {
console.log("🔧 Testing Basic Contract Connection");
console.log("==================================");
const rpcUrl = "https://testnet.evm.nodes.onflow.org";
const contractAddress = "0x756523eDF6FfC690361Df3c61Ec3719F77e9Aa1a";
const publicClient = createPublicClient({
chain: worldchainSepolia,
transport: http(rpcUrl),
});
try {
// Test 1: Check contract exists
console.log("📋 Step 1: Checking if contract exists...");
const code = await publicClient.getCode({ address: contractAddress });
if (code === "0x") {
console.log("❌ Contract does not exist at this address");
return;
}
console.log("✅ Contract exists");
// Test 2: Try to call a simple view function
console.log("\n📋 Step 2: Testing simple contract call...");
// Try to get the order count
const orderCountABI = [
{
inputs: [],
name: "s_orderCount",
outputs: [
{ internalType: "uint256", name: "", type: "uint256" },
],
stateMutability: "view",
type: "function",
},
];
try {
const orderCount = await publicClient.readContract({
address: contractAddress,
abi: orderCountABI,
functionName: "s_orderCount",
});
console.log(`✅ Order count: ${orderCount.toString()}`);
} catch (error) {
console.log("❌ Failed to read order count:", error.message);
}
// Test 3: Try to read an order with a simple ID
console.log("\n📋 Step 3: Testing order reading...");
const orderABI = [
{
inputs: [
{
internalType: "bytes32",
name: "_orderId",
type: "bytes32",
},
],
name: "getOrder",
outputs: [
{
components: [
{
internalType: "address",
name: "maker",
type: "address",
},
{
internalType: "address",
name: "taker",
type: "address",
},
{
internalType: "string",
name: "recipientUpiAddress",
type: "string",
},
{
internalType: "uint256",
name: "amount",
type: "uint256",
},
{
internalType: "uint256",
name: "startPrice",
type: "uint256",
},
{
internalType: "uint256",
name: "acceptedPrice",
type: "uint256",
},
{
internalType: "uint256",
name: "endPrice",
type: "uint256",
},
{
internalType: "uint256",
name: "startTime",
type: "uint256",
},
{
internalType: "uint256",
name: "acceptedTime",
type: "uint256",
},
{
internalType: "bool",
name: "accepted",
type: "bool",
},
{
internalType: "bool",
name: "fullfilled",
type: "bool",
},
],
internalType: "struct OrderProtocol.Order",
name: "",
type: "tuple",
},
],
stateMutability: "view",
type: "function",
},
];
// Try with a simple order ID (all zeros)
const testOrderId =
"0x0000000000000000000000000000000000000000000000000000000000000001";
console.log(`📤 Trying to read order: ${testOrderId}`);
try {
const orderData = await publicClient.readContract({
address: contractAddress,
abi: orderABI,
functionName: "getOrder",
args: [testOrderId],
});
console.log("✅ Order reading works!");
console.log(` Maker: ${orderData[0]}`);
console.log(` Accepted: ${orderData[10]}`);
} catch (error) {
console.log("❌ Order reading failed:", error.message);
// Try the problematic order ID
const problematicOrderId =
"0x3a3d6ac3379a4fd4f15776162dc0f3f2377d842883f91909e7d468175c489f7a";
console.log(`\n📤 Trying problematic order: ${problematicOrderId}`);
try {
const orderData2 = await publicClient.readContract({
address: contractAddress,
abi: orderABI,
functionName: "getOrder",
args: [problematicOrderId],
});
console.log("✅ Problematic order reading works!");
console.log(` Maker: ${orderData2[0]}`);
} catch (error2) {
console.log(
"❌ Problematic order reading failed:",
error2.message
);
}
}
} catch (error) {
console.error("❌ Test failed:", error.message);
}
}
testContractConnection().catch(console.error);