Skip to content

Commit

Permalink
FEAT: update the example with more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Riad-Quadratic committed Dec 20, 2022
1 parent 347a7d7 commit 7553643
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,7 @@ dist

.npmrc

*.js
*.js

# local folder for tests
local
101 changes: 101 additions & 0 deletions test/abi_demo2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
[
{
"members":[
{
"name":"low",
"offset":0,
"type":"felt"
},
{
"name":"high",
"offset":1,
"type":"felt"
}
],
"name":"Uint256",
"size":2,
"type":"struct"
},
{
"inputs":[
{
"name":"par1",
"type":"felt"
},
{
"name":"symbol",
"type":"felt"
},
{
"name":"decimals",
"type":"felt"
},
{
"name":"initial_supply",
"type":"Uint256"
},
{
"name":"recipient",
"type":"felt"
}
],
"name":"constructor",
"outputs":[

],
"type":"constructor"
},
{
"inputs":[

],
"name":"fun1",
"outputs":[
{
"name":"par1",
"type":"felt"
},
{
"name":"par2",
"type":"Uint256"
}
],
"stateMutability":"view",
"type":"function"
},
{
"inputs":[
{
"name":"x",
"type":"felt"
},
{
"name":"y",
"type":"felt"
}
],
"name":"fun2",
"outputs":[

],
"stateMutability":"view",
"type":"function"
},
{
"inputs":[
{
"name":"account",
"type":"felt"
}
],
"name":"balanceOf",
"outputs":[
{
"name":"balance",
"type":"Uint256"
}
],
"stateMutability":"view",
"type":"function"
}
]
12 changes: 9 additions & 3 deletions test/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ const ABI = [
{
'inputs': [],
'name': 'fun1',
'outputs': [{'name': 'par1', 'type': 'felt'}],
'outputs':
[{'name': 'par1', 'type': 'felt'}, {'name': 'par2', 'type': 'Uint256'}],
'stateMutability': 'view',
'type': 'function'
},
{
'inputs': [{'name': 'x', 'type': 'felt'}, {'name': 'y', 'type': 'felt'}],
'name': 'fun2',
'outputs': [{'name': 'par1', 'type': 'felt'}],
'outputs': [],
'stateMutability': 'view',
'type': 'function'
},
Expand All @@ -45,4 +46,9 @@ const ABI = [
}
] as const;

const [balance] = call(ABI, 'balanceOf', [123]);
// fun1 takes no input and returns [felt, Uint256]
const ret1 = call(ABI, 'fun1', []);
// fun2 takes two felts as input and has no output
const ret2 = call(ABI, 'fun2', [123, 321]);
// balanceOf takes one felt as input and returns a Uint256
const balance = call(ABI, 'balanceOf', 123);

0 comments on commit 7553643

Please sign in to comment.