Skip to content

Commit

Permalink
Merge pull request #1 from wallet-test-framework/better-cli
Browse files Browse the repository at this point in the history
remove hardcoded paths; fix changed id
  • Loading branch information
gaudren authored Nov 7, 2023
2 parents 7f05581 + 307ca4c commit d0acca4
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 37 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## Wallet Test Framework: Coinbase

A tool to automate the Coinbase wallet use use with Wallet Test Framework.

## Installation

### Node

This project requires Nodejs version 20.6 or later.

### Dependencies

```bash
npm install
```

### Chrome Extension

The glue requires a local copy of Coinbase Wallet. The publicly available extension may be fetched with:

```bash
wget \
-O coinbase.crx \
'https://clients2.google.com/service/update2/crx?response=redirect&prodversion=118.0.5993.70&acceptformat=crx2,crx3&x=id%3Dhnfanknocfeofbddgcijnmhnfnkdnaad%26uc'
```

## Building

```bash
npm run build
```

### Tests & Linting (Optional)

```bash
npm test
```

## Running

```bash
npx glue-coinbase \
--extension-path /path/to/crx/file
```
122 changes: 93 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"dependencies": {
"@wallet-test-framework/glue": "^0.7.0",
"@wallet-test-framework/glue-ws": "file:../glue-ws",
"@wallet-test-framework/glue-ws": "^0.1.0",
"meow": "^12.1.1",
"selenium-webdriver": "^4.14.0"
}
Expand Down
36 changes: 30 additions & 6 deletions src/glue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,16 @@ class CoinbaseDriver {
this.glue = glue;
}

public static async create(glue: CoinbaseGlue): Promise<CoinbaseDriver> {
public static async create(
glue: CoinbaseGlue,
extensionPath: string,
browserVersion: string | null | undefined,
): Promise<CoinbaseDriver> {
const chrome = new Chrome.Options();
chrome.setBrowserVersion("117.0.5938.149");
chrome.addExtensions("/home/sam/coinbase.crx");
if (typeof browserVersion === "string") {
chrome.setBrowserVersion(browserVersion);
}
chrome.addExtensions(extensionPath);

const driver = await new Builder()
.forBrowser("chrome")
Expand Down Expand Up @@ -276,13 +282,31 @@ class CoinbaseDriver {
export class CoinbaseGlue extends Glue {
private static async buildDriver(
glue: CoinbaseGlue,
extensionPath: string,
browserVersion: string | null | undefined,
): Promise<CoinbaseDriver> {
const coinbase = await CoinbaseDriver.create(glue);
const coinbase = await CoinbaseDriver.create(
glue,
extensionPath,
browserVersion,
);
await coinbase.setup();
return coinbase;
}

private readonly driver = CoinbaseGlue.buildDriver(this);
private readonly driver;

constructor(
extensionPath: string,
browserVersion: string | null | undefined,
) {
super();
this.driver = CoinbaseGlue.buildDriver(
this,
extensionPath,
browserVersion,
);
}

async launch(url: string): Promise<void> {
const cb = await this.driver;
Expand Down Expand Up @@ -310,7 +334,7 @@ export class CoinbaseGlue extends Glue {
await settingsLink.click();

const networksMenu = await driver.findElement(
By.css("[data-testid='settings-networks-menu-cell-pressable']"),
By.css("[data-testid='network-setting-cell-pressable']"),
);
await driver.wait(until.elementIsVisible(networksMenu), 2000);
await networksMenu.click();
Expand Down
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,24 @@ export async function main(args: string[]): Promise<void> {
argv: args.slice(2),
importMeta: import.meta,
flags: {
extensionPath: {
type: "string",
isRequired: true,
},
browserVersion: {
type: "string",
},
testUrl: {
type: "string",
default: "https://wallet-test-framework.herokuapp.com/",
},
},
});

const implementation = new CoinbaseGlue();
const implementation = new CoinbaseGlue(
cli.flags.extensionPath,
cli.flags.browserVersion,
);
const serveResult = serveGlue(implementation, { port: 0 });

try {
Expand Down

0 comments on commit d0acca4

Please sign in to comment.