Move and test loadTokenTickers
This commit is contained in:
parent
85cd71ddfe
commit
accef527fe
@ -8,12 +8,7 @@ import { isValidAddress } from "../../addresses";
|
||||
import * as constants from "../../constants";
|
||||
import { logAccountsState, logSendJob } from "../../debugging";
|
||||
import { Faucet } from "../../faucet";
|
||||
import {
|
||||
availableTokensFromHolder,
|
||||
identitiesOfFirstWallet,
|
||||
loadAccounts,
|
||||
loadTokenTickers,
|
||||
} from "../../multichainhelpers";
|
||||
import { availableTokensFromHolder, identitiesOfFirstWallet, loadAccounts } from "../../multichainhelpers";
|
||||
import { setSecretAndCreateIdentities } from "../../profile";
|
||||
import { SendJob } from "../../types";
|
||||
import { HttpError } from "./httperror";
|
||||
@ -55,7 +50,9 @@ export async function start(args: ReadonlyArray<string>): Promise<void> {
|
||||
|
||||
await setSecretAndCreateIdentities(profile, constants.mnemonic, connectedChainId);
|
||||
|
||||
const chainTokens = await loadTokenTickers(connection);
|
||||
const faucet = new Faucet(constants.tokenConfig, connection, connector.codec, profile);
|
||||
|
||||
const chainTokens = await faucet.loadTokenTickers();
|
||||
console.info("Chain tokens:", chainTokens);
|
||||
|
||||
const accounts = await loadAccounts(profile, connection);
|
||||
@ -71,8 +68,6 @@ export async function start(args: ReadonlyArray<string>): Promise<void> {
|
||||
|
||||
const distibutorIdentities = identitiesOfFirstWallet(profile).slice(1);
|
||||
|
||||
const faucet = new Faucet(constants.tokenConfig, connection, connector.codec, profile);
|
||||
|
||||
await faucet.refill();
|
||||
setInterval(async () => faucet.refill(), 60_000); // ever 60 seconds
|
||||
|
||||
|
||||
@ -107,4 +107,16 @@ describe("Faucet", () => {
|
||||
connection.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("loadTokenTickers", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutCosmos();
|
||||
const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultConfig);
|
||||
const { profile } = await makeProfile();
|
||||
const faucet = new Faucet(defaultConfig, connection, codec, profile);
|
||||
const tickers = await faucet.loadTokenTickers();
|
||||
expect(tickers).toEqual(["COSM", "STAKE"]);
|
||||
connection.disconnect();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -4,18 +4,14 @@ import {
|
||||
isBlockInfoFailed,
|
||||
isBlockInfoPending,
|
||||
SendTransaction,
|
||||
TokenTicker,
|
||||
TxCodec,
|
||||
} from "@iov/bcp";
|
||||
import { UserProfile } from "@iov/keycontrol";
|
||||
import { sleep } from "@iov/utils";
|
||||
|
||||
import { debugAccount, logAccountsState, logSendJob } from "./debugging";
|
||||
import {
|
||||
availableTokensFromHolder,
|
||||
identitiesOfFirstWallet,
|
||||
loadAccounts,
|
||||
loadTokenTickers,
|
||||
} from "./multichainhelpers";
|
||||
import { availableTokensFromHolder, identitiesOfFirstWallet, loadAccounts } from "./multichainhelpers";
|
||||
import { TokenManager } from "./tokenmanager";
|
||||
import { SendJob } from "./types";
|
||||
|
||||
@ -63,9 +59,13 @@ export class Faucet {
|
||||
}
|
||||
}
|
||||
|
||||
public async loadTokenTickers(): Promise<ReadonlyArray<TokenTicker>> {
|
||||
return (await this.connection.getAllTokens()).map(token => token.tokenTicker);
|
||||
}
|
||||
|
||||
public async refill(): Promise<void> {
|
||||
console.info(`Connected to network: ${this.connection.chainId()}`);
|
||||
console.info(`Tokens on network: ${(await loadTokenTickers(this.connection)).join(", ")}`);
|
||||
console.info(`Tokens on network: ${(await this.loadTokenTickers()).join(", ")}`);
|
||||
|
||||
const holderIdentity = identitiesOfFirstWallet(this.profile)[0];
|
||||
|
||||
|
||||
@ -33,12 +33,6 @@ export async function loadAccounts(
|
||||
return out;
|
||||
}
|
||||
|
||||
export async function loadTokenTickers(
|
||||
connection: BlockchainConnection,
|
||||
): Promise<ReadonlyArray<TokenTicker>> {
|
||||
return (await connection.getAllTokens()).map(token => token.tokenTicker);
|
||||
}
|
||||
|
||||
export function availableTokensFromHolder(holderAccount: Account): ReadonlyArray<TokenTicker> {
|
||||
return holderAccount.balance.map(coin => coin.tokenTicker);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user