-
Notifications
You must be signed in to change notification settings - Fork 799
feat: Implement Calldata Decoding to JSC Types #1018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AryanGodara
wants to merge
7
commits into
starknet-io:develop
Choose a base branch
from
AryanGodara:calldata-decoder-api-encoder
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4b6c6e7
initial commit after branch change
AryanGodara 3ed74bd
temp commit
AryanGodara 91a68b0
partial update decodeCalldata logic
AryanGodara 91c69c7
finalizing of helper function implementation pending
AryanGodara 1fd9baa
rewrite calldataEncoder
AryanGodara f921352
complete decompile
AryanGodara 764e316
fix: reset eslint, remove debug statements, remove array return type
AryanGodara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
node_modules/ | ||
dist/ | ||
www/ | ||
www/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { DecodeConfig } from '../../src/types'; | ||
|
||
import { | ||
BigNumberish, | ||
CairoUint256, | ||
CallData, | ||
Calldata, | ||
RawArgsArray, | ||
RawArgsObject, | ||
cairo, | ||
} from '../../src'; | ||
|
||
import { compiledComplexSierra } from '../config/fixtures'; | ||
|
||
const { tuple } = cairo; | ||
|
||
describe('Cairo 1', () => { | ||
test('should correctly compile and decompile complex data structures', async () => { | ||
type Order2 = { | ||
p1: BigNumberish; | ||
p2: BigNumberish[]; | ||
}; | ||
|
||
const myOrder2bis: Order2 = { | ||
// wrong order | ||
p2: ['abcd', '56ec'], | ||
p1: 'smolstring', | ||
}; | ||
|
||
const secondUint256: CairoUint256 = new CairoUint256(40000n); | ||
const tempUint256 = { low: 23456n, high: 1n } as CairoUint256; | ||
const thirdUint256: CairoUint256 = new CairoUint256(tempUint256); | ||
const myFalseUint256: CairoUint256 = thirdUint256; // wrong order | ||
|
||
const myRawArgsObject: RawArgsObject = { | ||
// wrong order | ||
active: true, | ||
symbol: 'NIT', | ||
initial_supply: myFalseUint256, | ||
recipient: '0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a', | ||
decimals: 18, | ||
tupoftup: tuple(tuple(34, 94), myFalseUint256), | ||
card: myOrder2bis, | ||
longText: 'Bug is back, for ever, here and everywhere', | ||
array1: [100, 101, 102], | ||
array2: [ | ||
[200, 201], | ||
[202, 203], | ||
[204, 205], | ||
], | ||
array3: [myOrder2bis, myOrder2bis], | ||
array4: [myFalseUint256, myFalseUint256], | ||
tuple1: tuple(secondUint256, myOrder2bis, [54, 55, 174], 59), | ||
name: 'niceToken', | ||
array5: [tuple(251, 40000), tuple(252, 40001)], | ||
}; | ||
|
||
const myRawArgsArray: RawArgsArray = [ | ||
'niceToken', | ||
'NIT', | ||
18, | ||
thirdUint256, | ||
{ p1: '17', p2: ['234', '467456745457', '0x56ec'] }, | ||
'0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a', | ||
true, | ||
{ '0': { '0': 34, '1': 94 }, '1': thirdUint256 }, | ||
'Bug is back, for ever, here and everywhere', | ||
['100', '101', '102'], | ||
[ | ||
[200, 201], | ||
[202, 203], | ||
[204, 205], | ||
], | ||
[ | ||
{ p1: '17', p2: ['234', '467456745457n', '0x56ec'] }, | ||
{ p1: '17', p2: ['234', '467456745457n', '0x56ec'] }, | ||
], | ||
[thirdUint256, thirdUint256], | ||
{ | ||
'0': secondUint256, | ||
'1': { p1: '17', p2: ['234', '467456745457n', '0x56ec'] }, | ||
'2': [54, 55, 56], | ||
'3': 59, | ||
}, | ||
[ | ||
{ '0': 251, '1': 40000 }, | ||
{ '0': 252, '1': 40001 }, | ||
], | ||
]; | ||
|
||
const config: DecodeConfig = { | ||
felt: String, | ||
'core::felt252': String, | ||
'core::integer::u8': Number, | ||
'core::integer::u16': Number, | ||
'core::integer::u64': Number, | ||
'core::integer::u128': BigInt, | ||
'core::starknet::contract_address::ContractAddress': String, | ||
longText: String, | ||
}; | ||
|
||
const cd: CallData = new CallData(compiledComplexSierra.abi); | ||
const compiledDataFromObject: Calldata = cd.compile('constructor', myRawArgsObject); | ||
const compiledDataFromArray: Calldata = cd.compile('constructor', myRawArgsArray); | ||
const decompiledDataFromObject = cd.decompile('constructor', compiledDataFromObject, config); | ||
const decompiledDataFromArray = cd.decompile('constructor', compiledDataFromArray, config); | ||
|
||
expect(decompiledDataFromObject).toEqual(myRawArgsObject); | ||
expect(decompiledDataFromArray).toEqual(myRawArgsObject); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.