-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring, contract dsl wasm compatibility, encode/decode fixes. (#108
) * Refactoring, contract dsl wasm compatibility, fixes in encoding/decoding. * Tests * Fixed Nim 1.* compatibility * Some backward compatibility * Minor tweaks, and a safety check * Update web3/encoding.nim Co-authored-by: Jacek Sieka <[email protected]> * Update web3.nim Co-authored-by: Jacek Sieka <[email protected]> * Use stew.assign instead of reinventing the wheel * Fixed string decoder. Removed extra allocations. * Added test for string decoder * v0.2.2 --------- Co-authored-by: Jacek Sieka <[email protected]> Co-authored-by: jangko <[email protected]>
- Loading branch information
1 parent
df0af1a
commit 45d09b2
Showing
7 changed files
with
635 additions
and
604 deletions.
There are no files selected for viewing
This file contains 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 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 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,35 @@ | ||
import pkg/unittest2 | ||
import ../web3 | ||
|
||
type | ||
PubKeyBytes = DynamicBytes[48, 48] | ||
WithdrawalCredentialsBytes = DynamicBytes[32, 32] | ||
SignatureBytes = DynamicBytes[96, 96] | ||
Int64LeBytes = DynamicBytes[8, 8] | ||
|
||
const logData = "00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000030b2f5263a3454de3a9116b0edaa3cfbb2795a99482ee268b7aed5b15b532d9b20c34b67c82877ba1326326f3ae6cc5ad3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020010000000000000000000000a3f7076718fa4fed91b5830a45489053eb367afb0000000000000000000000000000000000000000000000000000000000000008004059730700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000608ee47adfab0819ec0d9144a3f76c0a663f8d7d66a2cfd994eb5d23d15d779430ec85ecd3c91bf7b4d229a9c4a8bee83e0096913d0b05525307114d75fa9baf79b4634ba80d3d262dd769c66fb6af25bff30a5ce04600940d2271278fad5b3096000000000000000000000000000000000000000000000000000000000000000802f3000000000000000000000000000000000000000000000000000000000000" | ||
|
||
template init[N: static int](T: type DynamicBytes[N, N]): T = | ||
T newSeq[byte](N) | ||
|
||
suite "String decoders": | ||
test "Log message decoding": | ||
var | ||
pubkey = init PubKeyBytes | ||
withdrawalCredentials = init WithdrawalCredentialsBytes | ||
amount = init Int64LeBytes | ||
signature = init SignatureBytes | ||
index = init Int64LeBytes | ||
|
||
var offset = 0 | ||
offset += decode(logData, offset, pubkey) | ||
offset += decode(logData, offset, withdrawalCredentials) | ||
offset += decode(logData, offset, amount) | ||
offset += decode(logData, offset, signature) | ||
offset += decode(logData, offset, index) | ||
|
||
assert($pubkey == "0xb2f5263a3454de3a9116b0edaa3cfbb2795a99482ee268b7aed5b15b532d9b20c34b67c82877ba1326326f3ae6cc5ad3") | ||
assert($withdrawalCredentials == "0x010000000000000000000000a3f7076718fa4fed91b5830a45489053eb367afb") | ||
assert($amount == "0x0040597307000000") | ||
assert($signature == "0x8ee47adfab0819ec0d9144a3f76c0a663f8d7d66a2cfd994eb5d23d15d779430ec85ecd3c91bf7b4d229a9c4a8bee83e0096913d0b05525307114d75fa9baf79b4634ba80d3d262dd769c66fb6af25bff30a5ce04600940d2271278fad5b3096") | ||
assert($index == "0x02f3000000000000") |
Oops, something went wrong.