Skip to content

Commit

Permalink
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 56887a6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 33 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
69 changes: 37 additions & 32 deletions packages/cli/test/controller.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
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 } from "./setup";

describe("commands/controller", function () {
this.timeout("30s");
const defaultArgs = [
"--providerUrl",
TEST_PROVIDER_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 });

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

let tableName: string;
before(async function () {
Expand All @@ -30,7 +41,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 +59,10 @@ describe("commands/controller", function () {
"another",
"--privateKey",
privateKey,
"--providerUrl",
TEST_PROVIDER_URL,
"--chain",
"fooz",
])
.command(mod)
.parse();
Expand All @@ -63,8 +80,7 @@ describe("commands/controller", function () {
"invalid",
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
])
.command(mod)
.parse();
Expand All @@ -83,8 +99,7 @@ describe("commands/controller", function () {
"invalid",
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
])
.command(mod)
.parse();
Expand All @@ -102,8 +117,7 @@ describe("commands/controller", function () {
"invalid",
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
])
.command(mod)
.parse();
Expand All @@ -123,8 +137,7 @@ describe("commands/controller", function () {
tableName,
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
])
.command(mod)
.parse();
Expand All @@ -145,8 +158,7 @@ describe("commands/controller", function () {
tableName,
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
])
.command(mod)
.parse();
Expand All @@ -164,8 +176,7 @@ describe("commands/controller", function () {
tableName,
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
])
.command(mod)
.parse();
Expand All @@ -192,8 +203,7 @@ describe("commands/controller", function () {
"invalid",
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
"--aliases",
aliasesFilePath,
])
Expand All @@ -219,8 +229,7 @@ describe("commands/controller", function () {
"invalid",
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
"--aliases",
aliasesFilePath,
])
Expand All @@ -245,8 +254,7 @@ describe("commands/controller", function () {
"invalid",
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
"--aliases",
aliasesFilePath,
])
Expand Down Expand Up @@ -294,8 +302,7 @@ describe("commands/controller", function () {
tableAlias,
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
"--aliases",
aliasesFilePath,
])
Expand Down Expand Up @@ -345,8 +352,7 @@ describe("commands/controller", function () {
tableAlias,
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
"--aliases",
aliasesFilePath,
])
Expand Down Expand Up @@ -393,8 +399,7 @@ describe("commands/controller", function () {
tableAlias,
"--privateKey",
privateKey,
"--chain",
"local-tableland",
...defaultArgs,
"--aliases",
aliasesFilePath,
])
Expand Down

0 comments on commit 56887a6

Please sign in to comment.