UNPKG

@tangany/waas

Version:

node.js SDK for Tangany Wallet as a Service API

73 lines (50 loc) 2.62 kB
const { Waas, ETHEREUM_PUBLIC_NETWORK, BITCOIN_NETWORK, BITCOIN_TX_CONFIRMATIONS, BITCOIN_TX_SPEED, TimeoutError } = require("../dist"); const { config } = require("dotenv"); const { resolve } = require("path"); const assert = require("assert"); const { checkEnvVars } = require("./helpers"); const path = resolve(process.cwd(), ".env"); config({ path }); checkEnvVars(); describe("wait", function () { const wallet = process.env.E2E_WALLET; describe("Request", function () { const options = { ethereumNetwork: ETHEREUM_PUBLIC_NETWORK.GOERLI, // All tests execute on the goerli testnet }; this.timeout(160e3); it("should wait for an asynchronous request", async function () { const api = new Waas(options); const { wallet: newWallet } = await api.wallet().create(); const { address: newWalletAddress } = await api.wallet(newWallet).eth().get(); // Use the asynchronous sending of Ethereum transactions as an example, because this returns a request object. // One could also test it with any other method that returns this type. const txReq = await api.wallet(wallet).eth().sendAsync({ to: newWalletAddress, amount: "0.0001" }); const success = await txReq.wait(120e3, 1e3); console.log(success); await api.wallet(newWallet).delete(); }); it("should wait for an asynchronous request with given id", async function () { const api = new Waas(options); const { wallet: newWallet } = await api.wallet().create(); const { address: newWalletAddress } = await api.wallet(newWallet).eth().get(); // Perform an asynchronous Ethereum transaction to obtain a request ID. // This could also be any other action that returns a request object. const { id } = await api.wallet(wallet).eth().sendAsync({ to: newWalletAddress, amount: "0.0001" }); const success = await api.request(id).wait(120e3, 1e3); console.log(success); await api.wallet(newWallet).delete(); }); it("should time out for an asynchronous request", async function () { this.timeout(60e3); const api = new Waas(options); const { wallet: newWallet } = await api.wallet().create(); const { address: newWalletAddress } = await api.wallet(newWallet).eth().get(); // Use the asynchronous sending of Ethereum transactions as an example, because this returns a request object. // One could also test it with any other method that returns this type. const txReq = await api.wallet(wallet).eth().sendAsync({ to: newWalletAddress, amount: "0.0001" }); await assert.rejects(async () => txReq.wait(1e3)); await api.wallet(newWallet).delete(); }); }); });