-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: test: separate fixture docs; more test fixes
- Loading branch information
Showing
5 changed files
with
196 additions
and
234 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,19 @@ | ||
# Fixtures | ||
|
||
* Files with a fixed content that are used in the test suites. | ||
* TODO use `fetch` instead of Node FS API | ||
|
||
## Example mnemonics | ||
|
||
## Example contracts | ||
|
||
* **Echo contract** (build with `pnpm rs:build:example examples/echo`). | ||
Parrots back the data sent by the client, in order to validate | ||
reading/writing and serializing/deserializing the input/output messages. | ||
* **KV contract** (build with `pnpm rs:build:example examples/kv`). | ||
Exposes the key/value storage API available to contracts, | ||
in order to validate reading/writing and serializing/deserializing stored values. | ||
|
||
## Mocks | ||
|
||
### Mock agent |
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,47 +1,22 @@ | ||
# Fixtures | ||
|
||
* Files with a fixed content that are used in the test suites. | ||
* TODO use `fetch` instead of Node FS API | ||
|
||
```typescript | ||
import { withTmpDir } from '@hackbg/file' | ||
import { resolve, dirname } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { readFileSync } from 'node:fs' | ||
|
||
import $, { BinaryFile } from '@hackbg/file' | ||
import { Console, bold } from '@fadroma/agent' | ||
import $ from '@hackbg/file' | ||
``` | ||
import { StubAgent as Agent, StubChain as Chain, Uploader, Contract, Client } from '@fadroma/agent' | ||
|
||
```typescript | ||
export const here = dirname(fileURLToPath(import.meta.url)) | ||
export const workspace = resolve(here) | ||
export const fixture = x => resolve(here, x) | ||
export const log = new Console('Fadroma Testing') | ||
|
||
export const nullWasm = readFileSync(fixture('null.wasm')) | ||
``` | ||
|
||
## Example mnemonics | ||
|
||
```typescript | ||
export const mnemonics = [ | ||
'canoe argue shrimp bundle drip neglect odor ribbon method spice stick pilot produce actual recycle deposit year crawl praise royal enlist option scene spy', | ||
'bounce orphan vicious end identify universe excess miss random bench coconut curious chuckle fitness clean space damp bicycle legend quick hood sphere blur thing' | ||
] | ||
``` | ||
|
||
## Example contracts | ||
|
||
* **Echo contract** (build with `pnpm rs:build:example examples/echo`). | ||
Parrots back the data sent by the client, in order to validate | ||
reading/writing and serializing/deserializing the input/output messages. | ||
* **KV contract** (build with `pnpm rs:build:example examples/kv`). | ||
Exposes the key/value storage API available to contracts, | ||
in order to validate reading/writing and serializing/deserializing stored values. | ||
|
||
```typescript | ||
import $, { BinaryFile } from '@hackbg/file' | ||
import { readFileSync } from 'fs' | ||
|
||
export const examples = { | ||
} | ||
|
@@ -60,24 +35,19 @@ example('Empty', 'empty.wasm', 'e3b0c44298fc1c149afbf4c89 | |
example('KV', '[email protected]', '16dea8b55237085f24af980bbd408f1d6893384996e90e0ce2c6fc3432692a0d') | ||
example('Echo', '[email protected]', 'a4983efece1306aa897651fff74cae18436fc3280fc430d11a4997519659b6fd') | ||
example('Legacy', '[email protected]', 'a5d58b42e686d9f5f8443eb055a3ac45018de2d1722985c5f77bad344fc00c3b') | ||
``` | ||
|
||
## Mocks | ||
|
||
### Mock agent | ||
class MockChain extends Chain { | ||
uploads = new class MockUploader extends Uploader { | ||
resolve = () => `/tmp/fadroma-test-upload-${Math.floor(Math.random()*1000000)}` | ||
make = () => new class MockFile { | ||
resolve = () => `/tmp/fadroma-test-upload-${Math.floor(Math.random()*1000000)}` | ||
} | ||
} | ||
} | ||
|
||
```typescript | ||
import { Agent, Chain, Uploader, Contract, Client } from '@fadroma/agent' | ||
export const mockAgent = () => new class MockAgent extends Agent { | ||
|
||
chain = new (class MockChain extends Chain { | ||
uploads = new class MockUploader extends Uploader { | ||
resolve = () => `/tmp/fadroma-test-upload-${Math.floor(Math.random()*1000000)}` | ||
make = () => new class MockFile { | ||
resolve = () => `/tmp/fadroma-test-upload-${Math.floor(Math.random()*1000000)}` | ||
} | ||
} | ||
})('mock') | ||
chain = new MockChain('mock') | ||
|
||
async upload () { return {} } | ||
|
||
|
@@ -99,13 +69,9 @@ export const mockAgent = () => new class MockAgent extends Agent { | |
} | ||
|
||
} | ||
``` | ||
|
||
```typescript | ||
import { withTmpDir } from '@hackbg/file' | ||
export const tmpDir = () => { | ||
let x | ||
withTmpDir(dir=>x=dir) | ||
return x | ||
} | ||
``` |
Oops, something went wrong.