-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(as-sdk-tests): add tests for the tally convenience methods
- Loading branch information
1 parent
54a89d2
commit 3e0c023
Showing
4 changed files
with
171 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { JSON } from "json-as"; | ||
import { Tally, Process } from "../../as-sdk/assembly"; | ||
|
||
export function testTallyVmReveals(): void { | ||
const reveals = Tally.getReveals(); | ||
|
||
Process.exit_with_message(0, JSON.stringify(reveals)); | ||
} | ||
|
||
export function testTallyVmRevealsFiltered(): void { | ||
const reveals = Tally.getConsensusReveals(); | ||
|
||
Process.exit_with_message(0, JSON.stringify(reveals)); | ||
} |
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 |
---|---|---|
@@ -1,28 +1,25 @@ | ||
import { Process, httpFetch } from '../../as-sdk/assembly/index'; | ||
import { Process, httpFetch } from "../../as-sdk/assembly/index"; | ||
|
||
export function testTallyVmMode(): void { | ||
const envs = Process.envs(); | ||
const vmMode = envs.get('VM_MODE'); | ||
|
||
if (vmMode === 'tally') { | ||
Process.exit_with_message(0, 'tally'); | ||
} else { | ||
Process.exit_with_message(1, 'dr'); | ||
if (Process.isTallyVmMode()) { | ||
Process.exit_with_message(0, "tally"); | ||
} else if (Process.isDrVmMode()) { | ||
Process.exit_with_message(1, "dr"); | ||
} | ||
|
||
throw new Error(`Unknown VM mode: ${Process.getVmMode()}`); | ||
} | ||
|
||
export function testTallyVmHttp(): void { | ||
const response = httpFetch('https://swapi.dev/api/planets/1/'); | ||
const response = httpFetch("https://swapi.dev/api/planets/1/"); | ||
const fulfilled = response.fulfilled; | ||
const rejected = response.rejected; | ||
|
||
if (fulfilled !== null) { | ||
Process.exit_with_message(1, 'this should not be allowed in tally mode'); | ||
Process.exit_with_message(1, "this should not be allowed in tally mode"); | ||
} | ||
|
||
if (rejected !== null) { | ||
Process.exit_with_result(0, rejected.bytes); | ||
} | ||
} | ||
|
||
|
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