forked from keep-starknet-strange/madara
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrpc_cmp
executable file
·192 lines (164 loc) · 3.95 KB
/
rpc_cmp
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
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
help() {
echo "Usage: [--deoxys=\"http://127.0.0.1:9944\"] [--pathfinder...] command args..."
}
# ================= #
# PARSING ARGUMENTS #
# ================= #
if [ $# -lt 2 ]; then
help
exit 1
fi
OPTIONS=$(getopt -o '' -l deoxys:,pathfinder: -- "$@")
if [ $? != 0 ]; then
help
exit 1
fi
eval set -- "$OPTIONS"
PROVIDER_DEOXYS="http://127.0.0.1:9944"
PROVIDER_PATHFINDER=""
while true; do
case "$1" in
--deoxys)
PROVIDER_DEOXYS="$2"
shift 2
;;
--pathfinder)
PROVIDER_PATHFINDER="$2"
shift 2
;;
--)
shift 1
break
;;
*)
break
;;
esac
done
# ================= #
# RPC METHODS #
# ================= #
rpc_call(){
local provider=$1
local method=$2
local params=$3
curl -s \
--request POST \
--url "$provider" \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data "
{
\"id\": 1,
\"jsonrpc\": \"2.0\",
\"method\": \"$method\",
\"params\": $params
}
" | jq --sort-keys
}
get_class(){
local provider=$1
local class_hash=$2
local output=$3
rpc_call "$provider" "starknet_getClass" "[
\"latest\",
\"$class_hash\"
]" | jq 'del(.result.program)' > "$output"
}
get_class_at(){
local provider=$1
local contract_address=$2
local output=$3
rpc_call "$provider" "starknet_getClassAt" "[
\"latest\",
\"$contract_address\"
]" | jq 'del(.result.program)' > "$output"
}
get_class_hash_at(){
local provider=$1
local contract_address=$2
local output=$3
rpc_call "$provider" "starknet_getClassHashAt" "[
\"latest\",
\"$contract_address\"
]" > "$output"
}
get_storage_at(){
local provider=$1
local contract_addr=$2
local key=$3
local output=$4
rpc_call "$provider" "starknet_getStorageAt" "[
\"$contract_addr\",
\"$key\",
\"latest\"
]" > "$output"
}
get_block_with_tx(){
local provider=$1
local block_number=$2
local output=$3
rpc_call "$provider" "starknet_getBlockWithTxs" "[
{
\"block_number\": $block_number
}
]" > "$output"
}
# ================= #
# PROGRAM #
# ================= #
OUTPUT_DEOXYS="output_deoxys.json"
OUTPUT_PATHFINDER="output_pathfinder.json"
COMMAND=$1
shift 1
validate_args(){
local arg_count=$1
local target=$2
if [ $arg_count -ne $target ]; then
echo "❌ Invalid RPC argument count"
exit 1
fi
}
case $COMMAND in
getClass)
echo "🧪 Testing starknet_getClass"
validate_args $# 1
get_class "$PROVIDER_DEOXYS" "$1" "$OUTPUT_DEOXYS"
get_class "$PROVIDER_PATHFINDER" "$1" "$OUTPUT_PATHFINDER"
;;
getClassAt)
echo "🧪 Testing starknet_getClassAt"
validate_args $# 1
get_class_at "$PROVIDER_DEOXYS" "$1" "$OUTPUT_DEOXYS"
get_class_at "$PROVIDER_PATHFINDER" "$1" "$OUTPUT_PATHFINDER"
;;
getClassHashAt)
echo "🧪 Testing starknet_getClassHashAt"
validate_args $# 2
get_class_hash_at "$PROVIDER_DEOXYS" "$1" "$2" "$OUTPUT_DEOXYS"
get_class_hash_at "$PROVIDER_PATHFINDER" "$1" "$2" "$OUTPUT_PATHFINDER"
;;
getBlockWithTxs)
echo "🧪 Testing starknet_getBlockWithTxs"
validate_args $# 2
get_block_with_tx "$PROVIDER_DEOXYS" "$1" "$OUTPUT_DEOXYS"
get_block_with_tx "$PROVIDER_PATHFINDER" "$1" "$OUTPUT_PATHFINDER"
;;
*)
echo "Invalid argument: $COMMAND"
exit 1
;;
esac
diff output_deoxys.json output_pathfinder.json
if [ $? -eq 0 ]; then
if [ -s "$OUTPUT_DEOXYS" ]; then
echo "✅ RPC results match"
exit 0
fi
echo "❌ Ouput files are empty"
exit 1
else
echo "❌ RPC results don't match"
exit 1
fi