-
Notifications
You must be signed in to change notification settings - Fork 15
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
[Arbitrary Txs] Fix array encoding issue #4126
base: master
Are you sure you want to change the base?
Conversation
* Parses a string representation of an array into an array of values. | ||
* It supports nested arrays and handles strings within arrays. | ||
*/ | ||
const getArrayFromString = (value: string, type: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is loosely based on Dapp implementation but has further improvements such as actually parsing nested arrays and handling potentially confusing strings containing commas and brackets (e.g. ["[", ","]
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
if (!value.startsWith('[') || !value.endsWith(']')) { | ||
throw new Error('Invalid array format'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would propose moving this to translation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work @jakubcolony 🥇
Created a custom transaction via Permissions
with the provided values
Created another custom transaction via Reputation
Really nice implementation for the getArrayFromString
utils 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
This PR fixes an issue with array encoding when creating arbitrary transactions. The cause of the issue was passing a string representation of an array (e.g.
"[]"
) instead of a "first-class" JS array.It also improves the decoding of array arguments when showing a completed action.
Testing
To ensure thorough coverage, we'll deploy a test contract that has a function with nearly all possible argument types.
Deploying test contract
TestContract.sol
in your CDapp root directory with the following contents:npm run hardhat
, then run the following code line-by-line:The last expression will print the address of the newly deployed contract. Copy it for later use.
Testing arbitrary transactions
testFunction
from the dropdown, and fill the fields with correct values according to their type. For example:123456789
[123, 456, 789]
[[1, 2], [3, 4, 5]]
true
[true, false, true]
0x742d35Cc6634C0532925a3b844Bc454e4438f44e
[0x742d35Cc6634C0532925a3b844Bc454e4438f44e, 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4]
0xFF
[0xFF, 0xAA]
Hello World
["Hello", "World", "Blockchain"]
Submit the form. The transaction should go through and you should see the decoded arguments in the temporary completed action view.
Repeat the steps using reputation or multi-sig decision method (both use the same code).
Resolves #4124