continue rework
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
"main": "./dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "jest --coverage --verbose false",
|
||||
"test": "jest --verbose false",
|
||||
"lint": "eslint src",
|
||||
"lint:fix": "eslint src --fix",
|
||||
"docs": "typedoc --out docs src/index.ts"
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
import validatorClient from "../../src/index";
|
||||
import { config } from "../test-utils/config";
|
||||
|
||||
let client: validatorClient;
|
||||
let mnemonic: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
mnemonic = validatorClient.randomMnemonic();
|
||||
client = await validatorClient.connect(
|
||||
mnemonic,
|
||||
config.NYMD_URL,
|
||||
config.VALIDATOR_API,
|
||||
config.CURRENCY_DENOM,
|
||||
config.MIXNET_CONTRACT,
|
||||
config.VESTING_CONTRACT
|
||||
);
|
||||
});
|
||||
|
||||
describe("perform a few non expensive network calls with the validator client", () => {
|
||||
test.skip("get all cached mixnodes", async () => {
|
||||
try {
|
||||
const response = await client.getCachedMixnodes();
|
||||
|
||||
//expect all mixnodes to have their owner address
|
||||
response.forEach((mixnodeDetails) => {
|
||||
expect(mixnodeDetails.owner).toHaveLength(43);
|
||||
});
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
test.skip("get minimium pledge amount for a mixnode", async () => {
|
||||
try {
|
||||
const response = await client.minimumMixnodePledge();
|
||||
|
||||
expect(response.amount).toBe("100000000");
|
||||
expect(response.denom).toBe(config.CURRENCY_DENOM);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
test.skip("get minimium gateway pledge amount", async () => {
|
||||
try {
|
||||
const response = await client.minimumGatewayPledge();
|
||||
|
||||
expect(response.amount).toBe("100000000");
|
||||
expect(response.denom).toBe(config.CURRENCY_DENOM as string);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
test.skip("ensure the correct mixnet address is being passed", () => {
|
||||
try {
|
||||
//should supply the given value from the client init
|
||||
const mixnet_contract = client.mixnetContract;
|
||||
expect(mixnet_contract).toStrictEqual(config.MIXNET_CONTRACT);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
test.skip("ensure the correct vesting address is being passed", () => {
|
||||
try {
|
||||
const vesting_contract = client.vestingContract;
|
||||
expect(vesting_contract).toStrictEqual(config.VESTING_CONTRACT);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import validator from "../../src/index";
|
||||
import { ExecuteResult } from "@cosmjs/cosmwasm-stargate";
|
||||
import { Coin } from "@cosmjs/proto-signing";
|
||||
import { config } from "../test-utils/config";
|
||||
import {buildCoin, buildWallet, profitPercentage} from "../test-utils/utils"
|
||||
import {
|
||||
Gateway,
|
||||
GatewayOwnershipResponse,
|
||||
@@ -26,7 +26,7 @@ beforeEach(async () => {
|
||||
});
|
||||
|
||||
describe("long running e2e tests", () => {
|
||||
test.only("token transfer", async () => {
|
||||
test.skip("token transfer", async () => {
|
||||
try {
|
||||
//make sure there's enough balance in the wallet
|
||||
|
||||
@@ -61,7 +61,7 @@ describe("long running e2e tests", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test.only("update mixnode profit percentage", async () => {
|
||||
test.skip("update mixnode profit percentage", async () => {
|
||||
const nodeIdentity = config.MIXNODE_IDENTITY;
|
||||
const profitPercent = profitPercentage();
|
||||
|
||||
@@ -81,7 +81,7 @@ describe("long running e2e tests", () => {
|
||||
expect(ownsMixNode.mixnode?.mix_node.profit_margin_percent).toStrictEqual(profitPercent);
|
||||
});
|
||||
|
||||
test.only("unbond and bond mixnode", async () => {
|
||||
test.skip("unbond and bond mixnode", async () => {
|
||||
|
||||
try {
|
||||
await validatorClient.unbondMixNode("auto", "unbond-mixnode");
|
||||
@@ -161,7 +161,7 @@ describe("long running e2e tests", () => {
|
||||
expect(ownsGateway.address).toStrictEqual(config.USER_WALLET_ADDRESS);
|
||||
});
|
||||
|
||||
test.only("delegate to mixnode, then undelegate", async () => {
|
||||
test.skip("delegate to mixnode, then undelegate", async () => {
|
||||
|
||||
const pledge = buildCoin("100000000", config.CURRENCY_DENOM)
|
||||
|
||||
@@ -171,6 +171,7 @@ describe("long running e2e tests", () => {
|
||||
pledge,
|
||||
"auto"
|
||||
);
|
||||
//todo - we can assert the events for responses
|
||||
response.logs.forEach((log) => {
|
||||
console.log(log.events);
|
||||
console.log(log.log);
|
||||
@@ -186,8 +187,7 @@ describe("long running e2e tests", () => {
|
||||
"auto"
|
||||
);
|
||||
|
||||
//see output of events
|
||||
//remove shortly
|
||||
//todo - we can assert the events for responses
|
||||
unbond.logs.forEach((logs) => {
|
||||
logs.events.forEach((events) => {
|
||||
console.log(events.type);
|
||||
@@ -199,27 +199,3 @@ describe("long running e2e tests", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const profitPercentage = (): number => {
|
||||
return Math.floor(Math.random() * 100) + 1;
|
||||
};
|
||||
|
||||
|
||||
const buildCoin = (amount: string, denomination: string): Coin => {
|
||||
return {
|
||||
denom: `u${denomination}`,
|
||||
amount: amount,
|
||||
};
|
||||
};
|
||||
|
||||
const buildWallet = async (): Promise<string> => {
|
||||
let mnemonic = validator.randomMnemonic();
|
||||
|
||||
const randomAddress = await validator.mnemonicToAddress(
|
||||
mnemonic,
|
||||
config.NETWORK_BECH
|
||||
);
|
||||
console.log(randomAddress);
|
||||
return randomAddress;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
import SigningClient from "../../src/signing-client";
|
||||
import validator from "../../src/index";
|
||||
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";
|
||||
import { config } from "../test-utils/config";
|
||||
|
||||
let cosmWasmClient: CosmWasmClient;
|
||||
let mnemonic: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
cosmWasmClient = await SigningClient.connect(config.NYMD_URL);
|
||||
});
|
||||
|
||||
describe("peform basic network checks with the client", () => {
|
||||
test.skip("retrieve a newly created users balance should be empty", async () => {
|
||||
try {
|
||||
mnemonic = validator.randomMnemonic();
|
||||
|
||||
const randomAddress = await validator.mnemonicToAddress(
|
||||
mnemonic,
|
||||
config.NETWORK_BECH
|
||||
);
|
||||
|
||||
const balance = await cosmWasmClient.getBalance(
|
||||
randomAddress,
|
||||
config.CURRENCY_DENOM
|
||||
);
|
||||
|
||||
expect(balance.denom).toStrictEqual(config.CURRENCY_DENOM);
|
||||
expect(balance.amount).toStrictEqual("0");
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
test.skip("get the chain id of the network", async () => {
|
||||
try {
|
||||
const chainId = await cosmWasmClient.getChainId();
|
||||
expect(chainId).toStrictEqual(config.CHAIN_ID);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
test.skip("get height then search for it by it's block", async () => {
|
||||
try {
|
||||
const height = await cosmWasmClient.getHeight();
|
||||
const block = await cosmWasmClient.getBlock(height);
|
||||
|
||||
expect(block.header.chainId).toStrictEqual(config.CHAIN_ID);
|
||||
expect(block.header.height).toStrictEqual(height);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,26 +0,0 @@
|
||||
import ValidatorApiQuerier from "../../src/validator-api-querier";
|
||||
import { config } from "../test-utils/config";
|
||||
|
||||
let client: ValidatorApiQuerier;
|
||||
|
||||
beforeEach(() => {
|
||||
client = new ValidatorApiQuerier(config.VALIDATOR_API);
|
||||
});
|
||||
|
||||
describe("init the validator api querier", () => {
|
||||
test.skip("get rewarded mixnodes", async () => {
|
||||
try {
|
||||
//all mixnodes will have their owners address
|
||||
let response = await client.getRewardedMixnodes();
|
||||
|
||||
console.log(response);
|
||||
|
||||
//this is dependany on config and network amend shortly
|
||||
response.forEach((Node) => {
|
||||
expect(Node.owner.length).toStrictEqual(43);
|
||||
});
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Mock, Times } from "moq.ts";
|
||||
import { Block, BlockHeader } from "@cosmjs/stargate";
|
||||
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";
|
||||
|
||||
describe("implement cosmwasm client test", () => {
|
||||
test.only("get height of a block then search for it", async () => {
|
||||
let height = Promise.resolve(200);
|
||||
|
||||
let blockHeader = <BlockHeader>{
|
||||
version: {
|
||||
block: "200",
|
||||
app: "testing",
|
||||
},
|
||||
height: 200,
|
||||
chainId: "nym",
|
||||
time: "today",
|
||||
};
|
||||
|
||||
let block = Promise.resolve(<Block>{
|
||||
header: blockHeader,
|
||||
id: "test",
|
||||
txs: [],
|
||||
});
|
||||
|
||||
const getheight = new Mock<CosmWasmClient>()
|
||||
.setup((nym) => nym.getHeight())
|
||||
.returns(height);
|
||||
|
||||
const getblock = new Mock<CosmWasmClient>()
|
||||
.setup((nym) => nym.getBlock(200))
|
||||
.returns(block);
|
||||
|
||||
let heightC = getheight.object();
|
||||
let blockC = getblock.object();
|
||||
|
||||
let executeHeight = await heightC.getHeight();
|
||||
let executeBlock = await blockC.getBlock(200);
|
||||
|
||||
getheight.verify((nym) => nym.getHeight(), Times.Exactly(1));
|
||||
getblock.verify((nym) => nym.getBlock(200), Times.Exactly(1));
|
||||
|
||||
expect(executeHeight).toStrictEqual(await height);
|
||||
expect(executeBlock.header.height).toStrictEqual(await height);
|
||||
expect(executeBlock.header.chainId).toStrictEqual("nym");
|
||||
});
|
||||
});
|
||||
@@ -2,13 +2,9 @@ import { Mock, Times } from "moq.ts";
|
||||
import { INymdQuery } from "../../src/query-client";
|
||||
|
||||
describe("nym-client mocks", () => {
|
||||
beforeAll(() => {});
|
||||
|
||||
afterEach(() => {});
|
||||
|
||||
test.only("nymd mocks", async () => {
|
||||
test.only("gets interval rewarding percent", async () => {
|
||||
let contract = "mixnet_contract";
|
||||
let response = Promise.resolve(Number(200));
|
||||
let response = Promise.resolve(Number(2));
|
||||
|
||||
const client = new Mock<INymdQuery>()
|
||||
.setup((nym) => nym.getIntervalRewardPercent(contract))
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
import { Coin } from "@cosmjs/proto-signing";
|
||||
import { Mock, Times } from "moq.ts";
|
||||
import ValidatorClient from "../../src/index";
|
||||
import { DeliverTxResponse, logs } from "@cosmjs/stargate";
|
||||
import { Gateway, MixNode } from "../../src/types";
|
||||
import { ExecuteResult } from "@cosmjs/cosmwasm-stargate";
|
||||
import { config } from "../test-utils/config";
|
||||
import { buildWallet, buildCoin, profitPercentage } from "../test-utils/utils";
|
||||
import { promiseExecuteResult } from "../test-utils/expectedResults";
|
||||
|
||||
describe("mock validator client tests", () => {
|
||||
test.skip("token transfer", async () => {
|
||||
|
||||
//arrange
|
||||
//todo -- add more here
|
||||
let recipientAddress = "nymt14ev4p8qaa7ayr06cg3z7y2u2kxc9a8f4h9gkch";
|
||||
let sender = "nymt1cv59jumgvz2chn7ffst8tzvnapqzp282m5vat2";
|
||||
|
||||
const coin = buildCoin("50000", "nymt");
|
||||
|
||||
let transaction = Promise.resolve(<DeliverTxResponse>{
|
||||
code: 0,
|
||||
height: 1208302,
|
||||
rawLog: "[]",
|
||||
transactionHash:
|
||||
"9C7BF465AB5CAB0D62446CBB251CF89CD173A640C5DE8DBC14A4BB950916114E",
|
||||
gasUsed: 65042,
|
||||
gasWanted: 67977,
|
||||
});
|
||||
|
||||
console.log(transaction);
|
||||
|
||||
let mockClient = new Mock<ValidatorClient>()
|
||||
.setup((nym) => nym.send(recipientAddress, [coin], "auto", "test")).returns(transaction);
|
||||
|
||||
let token = mockClient.object();
|
||||
|
||||
//act
|
||||
let response = await token.send(recipientAddress, [coin], "auto", "test");
|
||||
|
||||
//assert
|
||||
mockClient.verify(cl => cl.send(recipientAddress, [coin], "auto"), Times.Exactly(1));
|
||||
});
|
||||
|
||||
test.only("bond mixnode test", async () => {
|
||||
//arrange
|
||||
let ownerSignature = "ownersignature";
|
||||
let coin = buildCoin("50000", "nymt");
|
||||
let expectedResult = promiseExecuteResult();
|
||||
|
||||
const profitPercent = profitPercentage();
|
||||
|
||||
const mixnode = <MixNode>{
|
||||
host: "1.1.1.1",
|
||||
mix_port: 1789,
|
||||
verloc_port: 1790,
|
||||
http_api_port: 8080,
|
||||
identity_key: "identity",
|
||||
sphinx_key: "identity",
|
||||
version: "0.12.1",
|
||||
profit_margin_percent: profitPercent,
|
||||
};
|
||||
|
||||
let client = new Mock<ValidatorClient>()
|
||||
.setup((client) =>
|
||||
client.bondMixNode(mixnode, ownerSignature, coin, "auto")
|
||||
)
|
||||
.returns(expectedResult);
|
||||
|
||||
let mixnodeBond = client.object();
|
||||
|
||||
//act
|
||||
let response = await mixnodeBond.bondMixNode(
|
||||
mixnode,
|
||||
ownerSignature,
|
||||
coin,
|
||||
"auto"
|
||||
);
|
||||
client.verify((cl) =>
|
||||
cl.bondMixNode(mixnode, ownerSignature, coin, "auto")
|
||||
);
|
||||
|
||||
//assert
|
||||
expect(response.logs[0].log).toStrictEqual("test");
|
||||
expect(response.transactionHash).toStrictEqual(
|
||||
"9C7BF465AB5CAB0D62446CBB251CF89CD173A640C5DE8DBC14A4BB950916114E"
|
||||
);
|
||||
});
|
||||
|
||||
test.only("un-bond mixnode", async () => {
|
||||
//arrange
|
||||
let expectedResult = promiseExecuteResult();
|
||||
|
||||
let client = new Mock<ValidatorClient>()
|
||||
.setup((client) => client.unbondMixNode("auto"))
|
||||
.returns(expectedResult);
|
||||
|
||||
let unbondNode = client.object();
|
||||
|
||||
//act
|
||||
let response = await unbondNode.unbondMixNode("auto");
|
||||
client.verify((cl) => cl.unbondMixNode("auto"));
|
||||
|
||||
//assert
|
||||
expect(response.logs[0].log).toStrictEqual("test");
|
||||
expect(response.transactionHash).toStrictEqual(
|
||||
"9C7BF465AB5CAB0D62446CBB251CF89CD173A640C5DE8DBC14A4BB950916114E"
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
test.only("bond gateway", async () => {
|
||||
//arrange
|
||||
let expectedResult = promiseExecuteResult();
|
||||
let ownerSignature = "ownersigntature";
|
||||
let coin = buildCoin("50000", "nymt");
|
||||
|
||||
const gateway = <Gateway>{
|
||||
host: '1.2.3.4',
|
||||
mix_port: 1789,
|
||||
clients_port: 9000,
|
||||
version: "0.12.1",
|
||||
sphinx_key: "sphinx_key",
|
||||
identity_key: "identity_key",
|
||||
location: "earth"
|
||||
};
|
||||
|
||||
let client = new Mock<ValidatorClient>()
|
||||
.setup((client) => client.bondGateway(gateway, ownerSignature, coin, "auto", "memo"))
|
||||
.returns(expectedResult);
|
||||
|
||||
let mock = client.object();
|
||||
|
||||
//act
|
||||
let response = await mock.bondGateway(gateway, ownerSignature, coin, "auto", "memo");
|
||||
client.verify((cl) => cl.bondGateway(gateway, ownerSignature, coin, "auto", "memo"));
|
||||
|
||||
//assert
|
||||
expect(response.logs[0].log).toStrictEqual("test");
|
||||
expect(response.transactionHash).toStrictEqual(
|
||||
"9C7BF465AB5CAB0D62446CBB251CF89CD173A640C5DE8DBC14A4BB950916114E"
|
||||
);
|
||||
});
|
||||
|
||||
test.only("unbond gateway", async () => {
|
||||
//arrange
|
||||
let expectedResult = promiseExecuteResult();
|
||||
let client = new Mock<ValidatorClient>()
|
||||
.setup((client) => client.unbondGateway())
|
||||
.returns(expectedResult);
|
||||
|
||||
let mock = client.object();
|
||||
|
||||
//act
|
||||
let response = await mock.unbondGateway();
|
||||
client.verify((cl) => cl.unbondGateway());
|
||||
|
||||
//assert
|
||||
expect(response.logs[0].log).toStrictEqual("test");
|
||||
expect(response.transactionHash).toStrictEqual(
|
||||
"9C7BF465AB5CAB0D62446CBB251CF89CD173A640C5DE8DBC14A4BB950916114E"
|
||||
);
|
||||
});
|
||||
|
||||
test.only("retrieve a newly created account and the balance should be empty", async () => {
|
||||
let nymWallet = await buildWallet();
|
||||
|
||||
let coin = Promise.resolve(<Coin>{
|
||||
denom: `${config.CURRENCY_DENOM}`,
|
||||
amount: "0",
|
||||
});
|
||||
|
||||
let client = new Mock<ValidatorClient>()
|
||||
.setup((nym) => nym.getBalance(nymWallet))
|
||||
.returns(coin);
|
||||
|
||||
let obj = client.object();
|
||||
|
||||
let execute = await obj.getBalance(nymWallet);
|
||||
|
||||
client.verify((nym) => nym.getBalance(nymWallet), Times.Exactly(1));
|
||||
|
||||
expect(execute).toStrictEqual(await coin);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { ExecuteResult } from "@cosmjs/cosmwasm-stargate";
|
||||
import { logs } from "@cosmjs/stargate";
|
||||
|
||||
export const promiseExecuteResult = (): Promise<ExecuteResult> => {
|
||||
let log = <logs.Log>{
|
||||
msg_index: 0,
|
||||
log: "test",
|
||||
events: [],
|
||||
};
|
||||
return Promise.resolve(<ExecuteResult>{
|
||||
logs: [log],
|
||||
transactionHash:
|
||||
"9C7BF465AB5CAB0D62446CBB251CF89CD173A640C5DE8DBC14A4BB950916114E",
|
||||
});
|
||||
};
|
||||
@@ -1,4 +1,8 @@
|
||||
// timer actions
|
||||
|
||||
import ValidatorClient, { Coin } from "../../src";
|
||||
import { config } from "./config";
|
||||
|
||||
// Store current time as `start`
|
||||
export const now = (eventName = null) => {
|
||||
if (eventName) {
|
||||
@@ -15,4 +19,28 @@ export const now = (eventName = null) => {
|
||||
}
|
||||
return duration;
|
||||
};
|
||||
|
||||
export const profitPercentage = (): number => {
|
||||
return Math.floor(Math.random() * 100) + 1;
|
||||
};
|
||||
|
||||
|
||||
export const buildCoin = (amount: string, denomination: string): Coin => {
|
||||
return {
|
||||
denom: `u${denomination}`,
|
||||
amount: amount,
|
||||
};
|
||||
};
|
||||
|
||||
export const buildWallet = async (): Promise<string> => {
|
||||
let mnemonic = ValidatorClient.randomMnemonic();
|
||||
|
||||
const randomAddress = await ValidatorClient.buildWallet(
|
||||
mnemonic,
|
||||
config.NETWORK_BECH
|
||||
);
|
||||
let accountdetails = await randomAddress.getAccounts();
|
||||
let nymWallet = accountdetails[0].address;
|
||||
return nymWallet;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user