Skip to content

Commit

Permalink
ref(tally): use Bytes instead of u8 for the RevealResult
Browse files Browse the repository at this point in the history
  • Loading branch information
FranklinWaller committed Sep 5, 2024
1 parent 5bca064 commit 07215d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions libs/as-sdk-integration-tests/src/tallyvm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('TallyVm', () => {

expect(result.exitCode).toBe(0);
expect(result.resultAsString).toBe(
'[{"salt":[115,101,100,97,95,115,100,107],"exit_code":0,"gas_used":"200000","reveal":[123,34,100,97,116,97,34,58,34,98,97,98,121,95,115,104,97,114,107,34,125],"in_consensus":0},{"salt":[115,101,100,97,95,115,100,107],"exit_code":1,"gas_used":"1336","reveal":[123,34,100,97,116,97,34,58,34,103,114,97,110,100,112,97,95,115,104,97,114,107,34,125],"in_consensus":0}]'
'[{\"salt\":{\"type\":\"hex\",\"value\":\"736564615f73646b\"},\"exit_code\":0,\"gas_used\":\"200000\",\"reveal\":{\"type\":\"hex\",\"value\":\"7b2264617461223a22626162795f736861726b227d\"},\"in_consensus\":0},{\"salt\":{\"type\":\"hex\",\"value\":\"736564615f73646b\"},\"exit_code\":1,\"gas_used\":\"1336\",\"reveal\":{\"type\":\"hex\",\"value\":\"7b2264617461223a226772616e6470615f736861726b227d\"},\"in_consensus\":0}]'
);
});

Expand Down Expand Up @@ -141,7 +141,7 @@ describe('TallyVm', () => {

expect(result.exitCode).toBe(0);
expect(result.resultAsString).toBe(
'[{"salt":[115,101,100,97,95,115,100,107],"exit_code":0,"gas_used":"1336","reveal":[123,34,100,97,116,97,34,58,34,103,114,97,110,100,112,97,95,115,104,97,114,107,34,125],"in_consensus":0},{"salt":[115,101,100,97,95,115,100,107],"exit_code":0,"gas_used":"1346","reveal":[123,34,100,97,116,97,34,58,34,99,111,117,115,105,110,95,115,104,97,114,107,34,125],"in_consensus":0}]'
'[{\"salt\":{\"type\":\"hex\",\"value\":\"736564615f73646b\"},\"exit_code\":0,\"gas_used\":\"1336\",\"reveal\":{\"type\":\"hex\",\"value\":\"7b2264617461223a226772616e6470615f736861726b227d\"},\"in_consensus\":0},{\"salt\":{\"type\":\"hex\",\"value\":\"736564615f73646b\"},\"exit_code\":0,\"gas_used\":\"1346\",\"reveal\":{\"type\":\"hex\",\"value\":\"7b2264617461223a22636f7573696e5f736861726b227d\"},\"in_consensus\":0}]'
);
});
});
10 changes: 6 additions & 4 deletions libs/as-sdk/assembly/tally.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { JSON } from "json-as/assembly";
import Process from "./process";
import { Bytes } from "./bytes";
import { jsonArrToUint8Array } from "./json-utils";

const REVEALS_ARGUMENT_POSITION = 2;
const CONSENSUS_ARGUMENT_POSITION = 3;
Expand All @@ -14,10 +16,10 @@ export class RevealBody {

@json
export class RevealResult {
salt!: u8[];
salt!: Bytes;
exit_code!: u8;
gas_used!: string;
reveal!: u8[];
reveal!: Bytes;
in_consensus!: u8;
}

Expand All @@ -44,8 +46,8 @@ export default class Tally {
revealResults.push({
exit_code: reveal.exit_code,
gas_used: reveal.gas_used,
reveal: reveal.reveal,
salt: reveal.salt,
reveal: Bytes.fromBytes(jsonArrToUint8Array(reveal.reveal)),
salt: Bytes.fromBytes(jsonArrToUint8Array(reveal.salt)),
in_consensus: consensus.at(index),
});
}
Expand Down

0 comments on commit 07215d9

Please sign in to comment.