Fix ABI encoding of outcome; should be in a tuple

This commit is contained in:
Mark Spanbroek 2021-02-23 12:30:55 +01:00
parent aaa394fc0c
commit 3867258fe6
3 changed files with 17 additions and 1 deletions

View File

@ -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

View File

@ -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,

View File

@ -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)