-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Integration tests for v1 (#103)
- Loading branch information
1 parent
28cf2f4
commit 1003b92
Showing
4 changed files
with
93 additions
and
3 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,15 @@ | ||
import { Ed25519KeyPairIdentity } from "../identity" | ||
|
||
export const SERVERS = { | ||
LEDGER: "http://127.0.0.1:8000", | ||
KEYVALUE: "http://127.0.0.1:8010", | ||
} | ||
|
||
export const ID1 = Ed25519KeyPairIdentity.fromPem(` | ||
-----BEGIN PRIVATE KEY----- | ||
MC4CAQAwBQYDK2VwBCIEIGgh+scXslP3zB4Jgkxtjf8vG60M9h4ZMjKg4RbxqWaG | ||
-----END PRIVATE KEY----- | ||
`) | ||
|
||
export const ID_RND = () => | ||
Ed25519KeyPairIdentity.fromMnemonic(Ed25519KeyPairIdentity.getMnemonic()) |
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,68 @@ | ||
import { Message } from "../message" | ||
import { CborData } from "../message/cbor" | ||
import { Base, Network } from "../network" | ||
import { ID1, ID_RND, SERVERS } from "./data" | ||
|
||
describe("Network", () => { | ||
let network: Network | ||
let HEX: string | ||
let CBOR_DATA: CborData | ||
|
||
beforeAll(() => { | ||
const timestamp = Math.floor(Date.now() / 1000).toString(16) | ||
HEX = `d28440a053d92711a2036673746174757305c11a${timestamp}40` | ||
CBOR_DATA = Buffer.from(HEX, "hex") | ||
}) | ||
|
||
it("should send encoded bytes", async () => { | ||
network = new Network(SERVERS.LEDGER) | ||
const status = await network.sendEncoded(CBOR_DATA) | ||
|
||
expect(status).toBeDefined() | ||
}) | ||
it("should send a request from bytes", async () => { | ||
network = new Network(SERVERS.LEDGER) | ||
const msg = Message.fromCborData(CBOR_DATA) | ||
const status = await network.send(msg) | ||
|
||
expect(status).toBeDefined() | ||
}) | ||
it("should send a request from an object", async () => { | ||
network = new Network(SERVERS.LEDGER) | ||
const msg = Message.fromObject({ method: "status" }) | ||
const status = await network.send(msg) | ||
|
||
expect(status).toBeDefined() | ||
}) | ||
it("should call a method", async () => { | ||
network = new Network(SERVERS.LEDGER) | ||
network.apply([Base]) | ||
const status = await network.call("status") | ||
|
||
expect(status).toBeDefined() | ||
}) | ||
it("should call a method from a shortcut", async () => { | ||
network = new Network(SERVERS.LEDGER) | ||
network.apply([Base]) | ||
|
||
const status = await network.base.status() | ||
|
||
expect(status).toBeDefined() | ||
}) | ||
it("should call a method with a known identity", async () => { | ||
network = new Network(SERVERS.LEDGER, ID1) | ||
network.apply([Base]) | ||
|
||
const status = await network.base.status() | ||
|
||
expect(status).toBeDefined() | ||
}) | ||
it("should call a method with a random identity", async () => { | ||
network = new Network(SERVERS.LEDGER, ID_RND()) | ||
network.apply([Base]) | ||
|
||
const status = await network.base.status() | ||
|
||
expect(status).toBeDefined() | ||
}) | ||
}) |
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