Skip to content

Commit

Permalink
chore: improve test logging
Browse files Browse the repository at this point in the history
Signed-off-by: Norman Meier <[email protected]>
  • Loading branch information
n0izn0iz committed Jan 20, 2024
1 parent 51d92fc commit 3ac39c8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
33 changes: 19 additions & 14 deletions packages/scripts/integration-testing/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const startCosmosLocalnet = async (
home = await fs.mkdtemp(path.join(tmpdir(), "cosmos-home-"));
// run teritorid init --chain-id=testing testing --home=$HOME/.teritorid
const initCmd = `${binaryPath} init testing --chain-id testing --home ${home}`;
console.log("> " + initCmd);
console.log("⚙️ " + initCmd);
await execPromise(initCmd);

await replaceInFile(
Expand All @@ -38,31 +38,31 @@ export const startCosmosLocalnet = async (

// run teritorid keys add validator --keyring-backend=test --home=$HOME/.teritorid
const addValidatorCmd = `${binaryPath} keys add validator --keyring-backend=test --home ${home}`;
console.log("> " + addValidatorCmd);
console.log("⚙️ " + addValidatorCmd);
await execPromise(addValidatorCmd);
// run teritorid add-genesis-account $(teritorid keys show validator -a --keyring-backend=test --home=$HOME/.teritorid) 100000000000utori,100000000000stake --home=$HOME/.teritorid
const addGenesisAccountCmd = `${binaryPath} add-genesis-account $(${binaryPath} keys show validator -a --keyring-backend=test --home ${home}) 100000000000000000utori,100000000000000000stake --home ${home}`;
console.log("> " + addGenesisAccountCmd);
console.log("⚙️ " + addGenesisAccountCmd);
await execPromise(addGenesisAccountCmd);
// run teritorid keys add testnet-adm --keyring-backend=test --home=$HOME/.teritorid
const addTestnetAdmCmd = `${binaryPath} keys add testnet-adm --keyring-backend=test --home ${home}`;
console.log("> " + addTestnetAdmCmd);
console.log("⚙️ " + addTestnetAdmCmd);
await execPromise(addTestnetAdmCmd);
// run teritorid add-genesis-account $(teritorid keys show validator -a --keyring-backend=test --home=$HOME/.teritorid) 100000000000utori,100000000000stake --home=$HOME/.teritorid
const addTestnetAdmGenesisAccountCmd = `${binaryPath} add-genesis-account $(${binaryPath} keys show testnet-adm -a --keyring-backend=test --home ${home}) 100000000000000000utori,100000000000000000stake --home ${home}`;
console.log("> " + addTestnetAdmGenesisAccountCmd);
console.log("⚙️ " + addTestnetAdmGenesisAccountCmd);
await execPromise(addTestnetAdmGenesisAccountCmd);
// run teritorid gentx validator 500000000stake --keyring-backend=test --home=$HOME/.teritorid --chain-id=testing
const gentxCmd = `${binaryPath} gentx validator 500000000stake --keyring-backend=test --home ${home} --chain-id=testing`;
console.log("> " + gentxCmd);
console.log("⚙️ " + gentxCmd);
await execPromise(gentxCmd);
// run teritorid collect-gentxs --home=$HOME/.teritorid
const collectGentxsCmd = `${binaryPath} collect-gentxs --home ${home}`;
console.log("> " + collectGentxsCmd);
console.log("⚙️ " + collectGentxsCmd);
await execPromise(collectGentxsCmd);
}
const cmd = `${binaryPath} start --home ${home}`;
console.log("> " + cmd);
console.log("⚙️ " + cmd);

const result = util.promisify(child_process.exec)(cmd, {
encoding: "utf-8",
Expand All @@ -82,7 +82,7 @@ export const startCosmosLocalnet = async (

const waitForHeight = async (port: number, targetHeight: bigint) => {
const statusCmd = `curl -s http://localhost:${port}/status`;
console.log("> " + statusCmd);
console.log("⏳ Waiting for height " + targetHeight);
while (true) {
try {
const result = await execPromise(statusCmd);
Expand All @@ -97,6 +97,7 @@ const waitForHeight = async (port: number, targetHeight: bigint) => {
} catch {}
await sleep(1000);
}
console.log("Reached height " + targetHeight);
};

export const upgradeCosmosLocalnet = async (
Expand All @@ -105,9 +106,11 @@ export const upgradeCosmosLocalnet = async (
validatorWalletName: string,
home: string,
) => {
console.log("⬆️ Upgrading chain to " + newVersion);

// get height
const statusCmd = `curl -s http://localhost:26657/status`;
console.log("> " + statusCmd);
console.log("⚙️ " + statusCmd);
// eslint-disable-next-line no-restricted-syntax
const status = JSON.parse(
(await execPromise(statusCmd, { encoding: "utf-8" })).stdout,
Expand All @@ -122,7 +125,7 @@ export const upgradeCosmosLocalnet = async (
--chain-id=testing --home=$HOME/.teritorid --yes -b block --deposit="100000000stake"
*/
const cmd = `${oldBinaryPath} tx gov submit-proposal software-upgrade "${newVersion}" --upgrade-height=${height} --title="Upgrade to ${newVersion}" --description="Upgrade to ${newVersion}" --from=${validatorWalletName} --keyring-backend=test --chain-id=testing --home=${home} --yes -b block --deposit="500000000stake" --node http://127.0.0.1:26657 -o json`;
console.log("> " + cmd);
console.log("⚙️ " + cmd);
const { stdout: out } = await execPromise(cmd, { encoding: "utf-8" });
const outObj = zodTryParseJSON(zodTxResult, out);
if (!outObj) {
Expand All @@ -134,14 +137,14 @@ export const upgradeCosmosLocalnet = async (
--home $HOME/.teritorid -b block -y --keyring-backend test
*/
const voteCmd = `${oldBinaryPath} tx gov vote ${proposalId} yes --from ${validatorWalletName} --chain-id testing --home ${home} -b block -y --keyring-backend test --node http://127.0.0.1:26657`;
console.log("> " + voteCmd);
console.log("⚙️ " + voteCmd);
await execPromise(voteCmd);

await waitForHeight(26657, height);

// check proposal status
const proposalCmd = `${oldBinaryPath} query gov proposal ${proposalId} --chain-id testing --home ${home} -o json --node http://127.0.0.1:26657`;
console.log("> " + proposalCmd);
console.log("⚙️ " + proposalCmd);
const { stdout: proposalOut } = await execPromise(proposalCmd, {
encoding: "utf-8",
});
Expand All @@ -154,6 +157,8 @@ export const upgradeCosmosLocalnet = async (
throw new Error("Proposal not passed");
}

console.log("🆙 Upgraded chain to " + newVersion);

return height;
};

Expand All @@ -162,7 +167,7 @@ export const buildCosmos = async (
binaryName: string,
): Promise<string> => {
const cmd = `cd ${repoPath} && make build`;
// console.log("> " + cmd);
// console.log("⚙️ " + cmd);
await new Promise((resolve, reject) => {
child_process.exec(cmd, (err, stdout, stderr) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion packages/scripts/integration-testing/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const cloneRepo = async (
): Promise<string> => {
const repoPath = await fs.mkdtemp(path.join(tmpdir(), "git-repo-"));
const cmd = `git clone ${repoURL} ${repoPath} && cd ${repoPath} && git checkout ${ref}`;
// console.log("> " + cmd);
// console.log("⚙️ " + cmd);
await new Promise((resolve, reject) => {
child_process.exec(cmd, (err, stdout, stderr) => {
if (err) {
Expand Down
8 changes: 5 additions & 3 deletions packages/scripts/network-setup/deployLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const instantiateNameService = async (
} --node ${injectRPCPort(
network.rpcEndpoint,
)} --yes --keyring-backend test -o json --home ${opts.home}`;
console.log("> " + cmd);
console.log("⚙️ " + cmd);
let { stdout: out } = await retry(5, async () => {
return await execPromise(cmd, {
encoding: "utf-8",
Expand Down Expand Up @@ -224,7 +224,7 @@ const instantiateContract = async (
)} --yes --keyring-backend test -o json --label ${sqh(
label,
)} --admin ${admin} --home ${opts.home}`;
console.log("> " + cmd);
console.log("⚙️ " + cmd);
let { stdout: out } = await retry(
5,
async () =>
Expand Down Expand Up @@ -257,7 +257,7 @@ const storeWASM = async (
} --node ${injectRPCPort(
network.rpcEndpoint,
)} --yes --keyring-backend test -o json --home ${opts.home}`;
console.log("> " + cmd);
console.log("⚙️ " + cmd);
let { stdout: out } = await retry(5, async () => {
return await execPromise(cmd, {
encoding: "utf-8",
Expand Down Expand Up @@ -292,6 +292,7 @@ const getTx = async (networkId: string, txhash: string, timeout?: number) => {
await sleep(timeout || 20000);
return undefined;
};
console.log("⏳ Waiting for tx '" + txhash + "'");
const tx = await Promise.race([startTimeout(), innerGetTx()]);
if (!tx) {
throw new Error("Timed out waiting for tx '" + txhash + "'");
Expand All @@ -306,6 +307,7 @@ const getTx = async (networkId: string, txhash: string, timeout?: number) => {
JSON.stringify(tx, null, 2),
);
}
console.log("Tx '" + txhash + "' found");
return tx;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/scripts/network-setup/restoreContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const main = async () => {
} --node ${injectRPCPort(destinationNetwork.rpcEndpoint)} -o json${
keyringBackend ? ` --keyring-backend ${keyringBackend}` : ""
}`;
console.log("> " + cmd);
console.log("⚙️ " + cmd);
const out = child_process.execSync(cmd, {
stdio: ["inherit", "pipe", "inherit"],
encoding: "utf-8",
Expand Down

0 comments on commit 3ac39c8

Please sign in to comment.