UNPKG

@tangany/waas

Version:

node.js SDK for Tangany Wallet as a Service API

79 lines (62 loc) 2.08 kB
const { config } = require("dotenv"); const { checkEnvVars } = require("./helpers"); const { EthereumPublicNetwork } = require("../src/waas"); const { Request } = require("../src/request"); const assert = require("assert"); const { resolve } = require("path"); const path = resolve(process.cwd(), ".env"); const { Waas } = require("../dist"); config({ path }); checkEnvVars(); describe("Sample workflows with requests", function() { this.timeout(0); const wallet = process.env.E2E_WALLET; const api = new Waas({ ethereumNetwork: EthereumPublicNetwork.GOERLI }); let sentRequests = []; const request = new Request(api); const config = { limit: 10, } before("create async requests", async function() { const recipient = { wallet, amount: "0.00001" } sentRequests.push((await api.wallet(wallet).eth().sendAsync(recipient)).id); recipient.amount = "0.000015" sentRequests.push((await api.wallet(wallet).eth().sendAsync(recipient)).id); }) it("should get request for given id", async function() { const request = await new Request(api, sentRequests[0]).get(); assert.ok(request.process); assert.ok(request.created); }); it("should list entire result pages", async function() { const requestIterable = request.list(config); let foundRequests = 0; for await (const page of requestIterable) { assert.ok(typeof page.hits.total === "number"); assert.ok(Array.isArray(page.list) && page.list.length <= config.limit); page.list.map(item => { assert.ok(item.requestId) if (sentRequests.includes(item.requestId)) { foundRequests++; } }) } assert.ok(foundRequests === sentRequests.length); }); it("should list gradual single requests of a result page", async function() { const requestIterable = await request.list(config, {autoPagination: true}); let foundRequests = 0; for await (const request of requestIterable) { assert.ok(request.requestId); if (sentRequests.includes(request.requestId)) { foundRequests++; } } assert.ok(foundRequests === sentRequests.length); }); })