mirror of
https://github.com/logos-storage/nim-nitro.git
synced 2026-01-06 23:53:11 +00:00
Fix ABI encoding of outcome; should be in a tuple
This commit is contained in:
parent
aaa394fc0c
commit
3867258fe6
@ -6,7 +6,7 @@ export types
|
||||
export abi
|
||||
|
||||
type
|
||||
Outcome* = seq[AssetOutcome]
|
||||
Outcome* = distinct seq[AssetOutcome]
|
||||
AssetOutcomeType* = enum
|
||||
allocationType = 0
|
||||
guaranteeType = 1
|
||||
@ -56,5 +56,10 @@ proc write*(writer: var AbiWriter, assetOutcome: AssetOutcome) =
|
||||
writer.write(content.finish())
|
||||
writer.finishTuple()
|
||||
|
||||
proc write*(writer: var AbiWriter, outcome: Outcome) =
|
||||
writer.startTuple()
|
||||
writer.write(seq[AssetOutcome](outcome))
|
||||
writer.finishTuple()
|
||||
|
||||
proc hashOutcome*(outcome: Outcome): array[32, byte] =
|
||||
keccak256.digest(Abi.encode(outcome)).data
|
||||
|
||||
@ -62,6 +62,9 @@ proc example*(_: type AssetOutcome): AssetOutcome =
|
||||
guarantee: Guarantee.example
|
||||
)
|
||||
|
||||
proc example*(_: type Outcome): Outcome =
|
||||
Outcome(seq[AssetOutcome].example)
|
||||
|
||||
proc example*(_: type State): State =
|
||||
State(
|
||||
turnNum: UInt48.example,
|
||||
|
||||
@ -59,6 +59,14 @@ suite "outcome":
|
||||
writer.finishTuple()
|
||||
check Abi.encode(assetOutcome) == writer.finish()
|
||||
|
||||
test "encodes outcomes":
|
||||
let outcome = Outcome.example()
|
||||
var writer: AbiWriter
|
||||
writer.startTuple()
|
||||
writer.write(seq[AssetOutcome](outcome))
|
||||
writer.finishTuple()
|
||||
check Abi.encode(outcome) == writer.finish()
|
||||
|
||||
test "hashes outcomes":
|
||||
let outcome = Outcome.example
|
||||
let encoded = Abi.encode(outcome)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user