Skip to content

Commit

Permalink
feat: 204 test
Browse files Browse the repository at this point in the history
Signed-off-by: Norman Meier <[email protected]>
  • Loading branch information
n0izn0iz committed Jan 19, 2024
1 parent 8853dff commit 495fcda
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ const repoURL = "https://github.com/TERITORI/teritori-chain.git";

const main = async () => {
const binaries = await buildBinaries(repoURL, "teritorid", [
"v2.0.3",
"v2.0.4",
] as const);

const {
home,
result: v203Result,
process: v203Process,
} = await startCosmosLocalnet(binaries["v2.0.3"]);
result: v204Result,
process: v204Process,
} = await startCosmosLocalnet(binaries["v2.0.4"]);

await deployTeritoriEcosystem(
{ binaryPath: binaries["v2.0.3"], home },
{ binaryPath: binaries["v2.0.4"], home },
teritoriLocalnetNetwork.id,
"testnet-adm",
);

// stop
v203Process.kill(os.constants.signals.SIGINT);
await v203Result;
v204Process.kill(os.constants.signals.SIGINT);
await v204Result;

await fs.rm(home, { recursive: true, force: true });
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const main = async () => {
"v1.3.0",
"v1.3.1",
"v1.4.2",
"v2.0.3",
"v2.0.4",
] as const);

const {
Expand Down Expand Up @@ -74,21 +74,21 @@ const main = async () => {
`minimum-gas-prices = "0stake"`,
);

const { process: v203Process, result: v203Result } =
await startCosmosLocalnet(binaries["v2.0.3"], {
const { process: v204Process, result: v204Result } =
await startCosmosLocalnet(binaries["v2.0.4"], {
home,
height: upgradeHeight,
});

// test cosmwasm
await deployTeritoriEcosystem(
{ binaryPath: binaries["v2.0.3"], home },
{ binaryPath: binaries["v2.0.4"], home },
teritoriLocalnetNetwork.id,
"testnet-adm",
);

v203Process.kill(os.constants.signals.SIGINT);
await v203Result;
v204Process.kill(os.constants.signals.SIGINT);
await v204Result;

await fs.rm(home, { recursive: true, force: true });
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const repoURL = "https://github.com/TERITORI/teritori-chain.git";
const main = async () => {
const binaries = await buildBinaries(repoURL, "teritorid", [
"v1.4.2",
"v2.0.3",
"v2.0.4",
] as const);

const {
Expand Down Expand Up @@ -48,8 +48,8 @@ const main = async () => {
);

// start next version
const { result, process: v203Process } = await startCosmosLocalnet(
binaries["v2.0.3"],
const { result, process: v204Process } = await startCosmosLocalnet(
binaries["v2.0.4"],
{
home,
height: upgradeHeight,
Expand All @@ -58,13 +58,13 @@ const main = async () => {

// test cosmwasm
await deployTeritoriEcosystem(
{ binaryPath: binaries["v2.0.3"], home },
{ binaryPath: binaries["v2.0.4"], home },
teritoriLocalnetNetwork.id,
"testnet-adm",
);

// stop
v203Process.kill(os.constants.signals.SIGINT);
v204Process.kill(os.constants.signals.SIGINT);
await result;

await fs.rm(home, { recursive: true, force: true });
Expand Down
54 changes: 40 additions & 14 deletions packages/scripts/network-setup/deployLib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IndexedTx } from "@cosmjs/stargate";
import { bech32 } from "bech32";
import child_process from "child_process";
import { cloneDeep } from "lodash";
import path from "path";
Expand All @@ -15,7 +16,7 @@ import {
mustGetNonSigningCosmWasmClient,
} from "../../networks";
import { zodTryParseJSON } from "../../utils/sanitize";
import { injectRPCPort, retry, zodTxResult } from "../lib";
import { injectRPCPort, retry, sleep, zodTxResult } from "../lib";
import sqh from "../sqh";

export const deployTeritoriEcosystem = async (
Expand All @@ -30,12 +31,16 @@ export const deployTeritoriEcosystem = async (
}
console.log(`Deploying to ${network.displayName}`);

const walletAddr = child_process
let walletAddr = child_process
.execSync(
`${opts.binaryPath} keys show --keyring-backend test -a ${wallet} --home ${opts.home}`,
)
.toString()
.trim();
if (walletAddr.startsWith("Successfully migrated")) {
walletAddr = walletAddr.substring(walletAddr.indexOf("\n")).trim();
}
bech32.decode(walletAddr);

console.log("Wallet address:", walletAddr);

Expand Down Expand Up @@ -186,11 +191,15 @@ const instantiateNameService = async (
network.rpcEndpoint,
)} --yes --keyring-backend test -o json --home ${opts.home}`;
console.log("> " + cmd);
const out = await retry(5, () =>
let out = await retry(5, () =>
child_process.execSync(cmd, {
stdio: ["inherit", "pipe", "inherit"],
encoding: "utf-8",
}),
);
if (!out.startsWith("{")) {
out = out.substring(out.indexOf("{"));
}
const outObj = zodTryParseJSON(zodTxResult, out.toString());
if (!outObj) {
throw new Error("Failed to parse instantiate result");
Expand Down Expand Up @@ -218,12 +227,16 @@ const instantiateContract = async (
label,
)} --admin ${admin} --home ${opts.home}`;
console.log("> " + cmd);
const out = await retry(5, () =>
let out = await retry(5, () =>
child_process.execSync(cmd, {
stdio: ["inherit", "pipe", "inherit"],
encoding: "utf-8",
}),
);
const outObj = zodTryParseJSON(zodTxResult, out.toString());
if (!out.startsWith("{")) {
out = out.substring(out.indexOf("{"));
}
const outObj = zodTryParseJSON(zodTxResult, out);
if (!outObj) {
throw new Error("Failed to parse instantiate result");
}
Expand All @@ -246,12 +259,15 @@ const storeWASM = async (
network.rpcEndpoint,
)} --yes --keyring-backend test -o json --home ${opts.home}`;
console.log("> " + cmd);
const out = await retry(5, () =>
let out = await retry(5, () =>
child_process.execSync(cmd, {
stdio: ["inherit", "pipe", "inherit"],
encoding: "utf-8",
}),
);
if (!out.startsWith("{")) {
out = out.substring(out.indexOf("{"));
}
const outObj = zodTryParseJSON(zodTxResult, out);
if (!outObj) {
throw new Error("Failed to parse store result");
Expand All @@ -262,14 +278,24 @@ const storeWASM = async (
return +codeId;
};

// FIXME: timeout
const getTx = async (networkId: string, txhash: string) => {
let tx: IndexedTx | null = null;
while (tx === null) {
tx = await retry(5, async () => {
const client = await mustGetNonSigningCosmWasmClient(networkId);
return client.getTx(txhash);
});
const getTx = async (networkId: string, txhash: string, timeout?: number) => {
const innerGetTx = async () => {
let tx: IndexedTx | null = null;
while (tx === null) {
tx = await retry(5, async () => {
const client = await mustGetNonSigningCosmWasmClient(networkId);
return client.getTx(txhash);
});
}
return tx;
};
const startTimeout = async () => {
await sleep(timeout || 50000);
return undefined;
};
const tx = await Promise.race([startTimeout(), innerGetTx()]);
if (!tx) {
throw new Error("Timed out waiting for tx '" + txhash + "'");
}
return tx;
};
Expand Down

0 comments on commit 495fcda

Please sign in to comment.