Skip to content

Commit

Permalink
WIP: merge monorepo changes into PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
joewagner committed Aug 22, 2023
1 parent df4b400 commit f27a6b6
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 252 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const _argv = yargs(hideBin(process.argv))
alias: "p",
type: "string",
description:
"JSON RPC API provider URL (e.g., https://eth-sepolia.g.alchemy.com/v2/123abc123a...)",
"JSON RPC API provider URL (e.g., https://eth-sepolia.g.alchemy.com/v2/123abc123a...)",
})
.option("aliases", {
alias: "a",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const handler = async (argv: Arguments<Options>): Promise<void> => {

const { registry } = await setupCommand({
...argv,
/* c8 ignore next 1 */ // can't test because of non-standard chain
chain: chain != null ? chain : chainId,
});

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export async function getWalletWithProvider({

// Second we will check if the "local-tableland" chain is being used,
// because the default provider won't work with this chain.
// note: can't test this since the cli tests are using non-standard port for chain
/* c8 ignore next 3 */
if (provider == null && network.chainName === "local-tableland") {
provider = new providers.JsonRpcProvider("http://127.0.0.1:8545");
}
Expand Down
80 changes: 42 additions & 38 deletions packages/cli/test/controller.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import { equal, match } from "node:assert";
import { getDefaultProvider } from "ethers";
import { describe, test, afterEach, before } from "mocha";
import { spy, restore } from "sinon";
import yargs from "yargs/yargs";
import { getAccounts, getDatabase } from "@tableland/local";
import { helpers, Database } from "@tableland/sdk";
import { Database } from "@tableland/sdk";
import { getAccounts } from "@tableland/local";
import { temporaryWrite } from "tempy";
import * as mod from "../src/commands/controller.js";
import { jsonFileAliases, logger, wait } from "../src/utils.js";
import { TEST_TIMEOUT_FACTOR, TEST_PROVIDER_URL, TEST_VALIDATOR_URL } from "./setup";

const defaultArgs = [
"--providerUrl",
TEST_PROVIDER_URL,
"--baseUrl",
TEST_VALIDATOR_URL,
"--chain",
"local-tableland",
];

const accounts = getAccounts();
const wallet = accounts[1];
const provider = getDefaultProvider(TEST_PROVIDER_URL, { chainId: 31337 });
const signer = wallet.connect(provider);
const db = new Database({ signer, autoWait: true });

describe("commands/controller", function () {
this.timeout("30s");

// account[0] is the Validator's wallet, try to avoid using that
const accounts = getAccounts();
const db = getDatabase(accounts[1]);
this.timeout(30000 * TEST_TIMEOUT_FACTOR);

let tableName: string;
before(async function () {
Expand All @@ -30,7 +43,9 @@ describe("commands/controller", function () {

test("throws without privateKey", async function () {
const consoleError = spy(logger, "error");
await yargs(["controller", "get", "blah"]).command(mod).parse();
await yargs(["controller", "get", "blah", ...defaultArgs])
.command(mod)
.parse();

const value = consoleError.getCall(0).firstArg;
equal(value, "missing required flag (`-k` or `--privateKey`)");
Expand All @@ -46,6 +61,10 @@ describe("commands/controller", function () {
"another",
"--privateKey",
privateKey,
"--providerUrl",
TEST_PROVIDER_URL,
"--chain",
"fooz",
])
.command(mod)
.parse();
Expand All @@ -63,8 +82,7 @@ describe("commands/controller", function () {
"invalid",
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
])
.command(mod)
.parse();
Expand All @@ -83,8 +101,7 @@ describe("commands/controller", function () {
"invalid",
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
])
.command(mod)
.parse();
Expand All @@ -102,8 +119,7 @@ describe("commands/controller", function () {
"invalid",
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
])
.command(mod)
.parse();
Expand All @@ -123,8 +139,7 @@ describe("commands/controller", function () {
tableName,
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
])
.command(mod)
.parse();
Expand All @@ -145,8 +160,7 @@ describe("commands/controller", function () {
tableName,
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
])
.command(mod)
.parse();
Expand All @@ -164,8 +178,7 @@ describe("commands/controller", function () {
tableName,
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
])
.command(mod)
.parse();
Expand All @@ -192,8 +205,7 @@ describe("commands/controller", function () {
"invalid",
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
"--aliases",
aliasesFilePath,
])
Expand All @@ -219,8 +231,7 @@ describe("commands/controller", function () {
"invalid",
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
"--aliases",
aliasesFilePath,
])
Expand All @@ -245,8 +256,7 @@ describe("commands/controller", function () {
"invalid",
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
"--aliases",
aliasesFilePath,
])
Expand All @@ -266,8 +276,7 @@ describe("commands/controller", function () {
});
// Create new db instance to enable aliases
const db = new Database({
signer: account,
baseUrl: helpers.getBaseUrl("local-tableland"),
signer,
autoWait: true,
aliases: jsonFileAliases(aliasesFilePath),
});
Expand All @@ -294,8 +303,7 @@ describe("commands/controller", function () {
tableAlias,
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
"--aliases",
aliasesFilePath,
])
Expand All @@ -318,8 +326,7 @@ describe("commands/controller", function () {
});
// Create new db instance to enable aliases
const db = new Database({
signer: account,
baseUrl: helpers.getBaseUrl("local-tableland"),
signer,
autoWait: true,
aliases: jsonFileAliases(aliasesFilePath),
});
Expand All @@ -345,8 +352,7 @@ describe("commands/controller", function () {
tableAlias,
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
"--aliases",
aliasesFilePath,
])
Expand All @@ -366,8 +372,7 @@ describe("commands/controller", function () {
});
// Create new db instance to enable aliases
const db = new Database({
signer: account,
baseUrl: helpers.getBaseUrl("local-tableland"),
signer,
autoWait: true,
aliases: jsonFileAliases(aliasesFilePath),
});
Expand All @@ -393,8 +398,7 @@ describe("commands/controller", function () {
tableAlias,
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
"--aliases",
aliasesFilePath,
])
Expand Down
Loading

0 comments on commit f27a6b6

Please sign in to comment.