Collect faucet data in object

This commit is contained in:
Simon Warta 2020-02-09 13:10:35 +01:00
parent 34c0f1e18f
commit ff78c296d4

View File

@ -25,9 +25,11 @@ const { fromBase64, fromHex, toAscii, toBase64, toHex } = Encoding;
const httpUrl = "http://localhost:1317";
const defaultNetworkId = "testing";
const faucetMnemonic =
"economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone";
const faucetAddress = "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6";
const faucet = {
mnemonic:
"economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone",
address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
};
const emptyAddress = "cosmos1ltkhnmdcqemmd2tkhnx7qx66tq7e0wykw2j85k";
const unusedAccount = {
address: "cosmos1cjsxept9rkggzxztslae9ndgpdyt2408lk850u",
@ -83,7 +85,7 @@ async function uploadContract(client: RestClient, pen: Pen): Promise<PostTxsResp
const theMsg: MsgStoreCode = {
type: "wasm/store-code",
value: {
sender: faucetAddress,
sender: faucet.address,
wasm_byte_code: toBase64(getRandomizedContract()),
source: "https://github.com/confio/cosmwasm/raw/0.7/lib/vm/testdata/contract_0.6.wasm",
builder: "cosmwasm-opt:0.6.2",
@ -99,7 +101,7 @@ async function uploadContract(client: RestClient, pen: Pen): Promise<PostTxsResp
gas: "89000000",
};
const account = (await client.authAccounts(faucetAddress)).result.value;
const account = (await client.authAccounts(faucet.address)).result.value;
const signBytes = makeSignBytes([theMsg], fee, defaultNetworkId, memo, account);
const signature = encodeSecp256k1Signature(pen.pubkey, await pen.createSignature(signBytes));
const signedTx = makeSignedTx(theMsg, fee, memo, signature);
@ -117,10 +119,10 @@ async function instantiateContract(
const theMsg: MsgInstantiateContract = {
type: "wasm/instantiate",
value: {
sender: faucetAddress,
sender: faucet.address,
code_id: codeId.toString(),
init_msg: {
verifier: faucetAddress,
verifier: faucet.address,
beneficiary: beneficiaryAddress,
},
init_funds: transferAmount || [],
@ -136,7 +138,7 @@ async function instantiateContract(
gas: "89000000",
};
const account = (await client.authAccounts(faucetAddress)).result.value;
const account = (await client.authAccounts(faucet.address)).result.value;
const signBytes = makeSignBytes([theMsg], fee, defaultNetworkId, memo, account);
const signature = encodeSecp256k1Signature(pen.pubkey, await pen.createSignature(signBytes));
const signedTx = makeSignedTx(theMsg, fee, memo, signature);
@ -152,7 +154,7 @@ async function executeContract(
const theMsg: MsgExecuteContract = {
type: "wasm/execute",
value: {
sender: faucetAddress,
sender: faucet.address,
contract: contractAddress,
msg: {},
sent_funds: [],
@ -168,7 +170,7 @@ async function executeContract(
gas: "89000000",
};
const account = (await client.authAccounts(faucetAddress)).result.value;
const account = (await client.authAccounts(faucet.address)).result.value;
const signBytes = makeSignBytes([theMsg], fee, defaultNetworkId, memo, account);
const signature = encodeSecp256k1Signature(pen.pubkey, await pen.createSignature(signBytes));
const signedTx = makeSignedTx(theMsg, fee, memo, signature);
@ -229,13 +231,13 @@ describe("RestClient", () => {
describe("post", () => {
it("can send tokens", async () => {
pendingWithoutCosmos();
const pen = await Secp256k1Pen.fromMnemonic(faucetMnemonic);
const pen = await Secp256k1Pen.fromMnemonic(faucet.mnemonic);
const memo = "My first contract on chain";
const theMsg: MsgSend = {
type: "cosmos-sdk/MsgSend",
value: {
from_address: faucetAddress,
from_address: faucet.address,
to_address: emptyAddress,
amount: [
{
@ -257,7 +259,7 @@ describe("RestClient", () => {
};
const client = new RestClient(httpUrl);
const account = (await client.authAccounts(faucetAddress)).result.value;
const account = (await client.authAccounts(faucet.address)).result.value;
const signBytes = makeSignBytes([theMsg], fee, defaultNetworkId, memo, account);
const signature = encodeSecp256k1Signature(pen.pubkey, await pen.createSignature(signBytes));
@ -269,7 +271,7 @@ describe("RestClient", () => {
it("can upload, instantiate and execute wasm", async () => {
pendingWithoutCosmos();
const pen = await Secp256k1Pen.fromMnemonic(faucetMnemonic);
const pen = await Secp256k1Pen.fromMnemonic(faucet.mnemonic);
const client = new RestClient(httpUrl);
const transferAmount: readonly Coin[] = [
@ -335,7 +337,7 @@ describe("RestClient", () => {
describe("query", () => {
it("can list upload code", async () => {
pendingWithoutCosmos();
const pen = await Secp256k1Pen.fromMnemonic(faucetMnemonic);
const pen = await Secp256k1Pen.fromMnemonic(faucet.mnemonic);
const client = new RestClient(httpUrl);
// check with contracts were here first to compare
@ -355,17 +357,17 @@ describe("RestClient", () => {
expect(newInfos.length).toEqual(numExisting + 1);
const lastInfo = newInfos[newInfos.length - 1];
expect(lastInfo.id).toEqual(codeId);
expect(lastInfo.creator).toEqual(faucetAddress);
expect(lastInfo.creator).toEqual(faucet.address);
// TODO: check code hash matches expectation
// expect(lastInfo.code_hash).toEqual(faucetAddress);
// expect(lastInfo.code_hash).toEqual(faucet.address);
// TODO: download code and check against auto-gen
});
it("can list contracts and get info", async () => {
pendingWithoutCosmos();
const pen = await Secp256k1Pen.fromMnemonic(faucetMnemonic);
const pen = await Secp256k1Pen.fromMnemonic(faucet.mnemonic);
const client = new RestClient(httpUrl);
const beneficiaryAddress = makeRandomAddress();
const transferAmount: readonly Coin[] = [
@ -409,7 +411,7 @@ describe("RestClient", () => {
// check out info
const myInfo = await client.getContractInfo(myAddress);
expect(myInfo.code_id).toEqual(codeId);
expect(myInfo.creator).toEqual(faucetAddress);
expect(myInfo.creator).toEqual(faucet.address);
expect((myInfo.init_msg as any).beneficiary).toEqual(beneficiaryAddress);
// make sure random addresses don't give useful info
@ -478,7 +480,7 @@ describe("RestClient", () => {
// we can query the verifier properly
const verifier = await client.queryContractSmart(contractAddress, { verifier: {} });
expect(verifier).toEqual(faucetAddress);
expect(verifier).toEqual(faucet.address);
// invalid query syntax throws an error
await client.queryContractSmart(contractAddress, { nosuchkey: {} }).then(