Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cli/src/cmd/chain-select.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { handleCliError } from '../cli-helpers/handleCliError.js';
import { getSpinner } from '../cli-helpers/spinner.js';
import * as color from '../cli-helpers/color.js';
import { readIAppConfig, writeIAppConfig } from '../utils/iAppConfigFile.js';
import { goToProjectRoot } from '../cli-helpers/goToProjectRoot.js';

export async function chainSelect({ chainName }: { chainName: string }) {
const spinner = getSpinner();
try {
await goToProjectRoot({ spinner });
spinner.text = 'Selecting chain';
const config = await readIAppConfig();
config.defaultChain = chainName;
await writeIAppConfig(config);
spinner.succeed(`Default chain set to ${color.file(chainName)}`);
} catch (error) {
handleCliError({ spinner, error });
}
}
15 changes: 15 additions & 0 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SUPPORTED_CHAINS } from './config/config.js';
import { checkPackageUpdate } from './cli-helpers/checkPackageUpdate.js';
import { walletImport } from './cmd/wallet-import.js';
import { walletSelect } from './cmd/wallet-select.js';
import { chainSelect } from './cmd/chain-select.js';

await checkPackageUpdate();

Expand Down Expand Up @@ -200,6 +201,20 @@ yargsInstance
},
})

.command({
command: 'chain select <chainName>',
describe: 'Select the default blockchain environment to use',
builder: (y) =>
y.positional('chainName', {
describe: 'Name of the blockchain to use',
choices: SUPPORTED_CHAINS,
demandOption: true,
}),
handler: (y) => {
return chainSelect(y);
},
})

.help()
.completion('completion', false) // create hidden "completion" command
.alias('help', 'h')
Expand Down
176 changes: 125 additions & 51 deletions cli/test/iapp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
createTestDir,
removeTestDir,
retry,
readIAppConfig,
} from './test-utils.ts';
import { fileURLToPath } from 'node:url';
import { readFile, rm, writeFile } from 'node:fs/promises';
Expand All @@ -30,16 +31,15 @@ beforeEach(async (t) => {

afterEach(async () => {
// remove test directory after each test
// comment the line below to keep the test directories for debugging
// comment the line below to keep the test directories for ging
await removeTestDir(testDir);
});

test('iapp help command works', async () => {
const { findByText, debug, clear } = await render(IAPP_COMMAND, ['help'], {
const { findByText, clear } = await render(IAPP_COMMAND, ['help'], {
cwd: testDir,
});
await findByText('iapp <cmd> [args]');
// debug();
clear();
});

Expand All @@ -50,37 +50,116 @@ test('iapp -v command works', async () => {
);
const { version } = packageJson;

const { findByText, debug, clear } = await render(IAPP_COMMAND, ['-v'], {
const { findByText, clear } = await render(IAPP_COMMAND, ['-v'], {
cwd: testDir,
});
await findByText(version);
// debug();
clear();
});

test('iapp init command works', async () => {
const { findByText, clear, debug, userEvent } = await render(
const { findByText, clear, userEvent } = await render(
IAPP_COMMAND,
['init'],
{
cwd: testDir,
}
);
await findByText("What's your project name?");
// debug();
clear();
userEvent.keyboard('[Enter]');
await findByText('Which language do you want to use?');
// debug();
clear();
userEvent.keyboard('[Enter]');
await findByText('What kind of project do you want to init?');
// debug();
clear();
userEvent.keyboard('[Enter]');
await findByText('Steps to Get Started:');
// debug();
clear();

const config = await readIAppConfig(join(testDir, 'hello-world'));
// default chain is bellecour
assert.strictEqual(
config.defaultChain,
'bellecour',
'defaultChain should be bellecour'
);
// default project name is hello-world
assert.strictEqual(
config.projectName,
'hello-world',
'projectName should be hello-world'
);
// default template is JavaScript
assert.strictEqual(
config.template,
'JavaScript',
'template should be JavaScript'
);
// default app secret is disabled
assert.strictEqual(config.appSecret, null, 'appSecret should be null');
// default wallet private key is set
assert(config.walletPrivateKey, 'walletPrivateKey should be set');
});

describe('iapp chain select', () => {
const projectName = 'test-iapp';
beforeEach(async () => {
await initIappProject({
testDir,
projectName,
template: 'JavaScript',
projectType: 'Hello World',
});
});

test('select bellecour works', async () => {
await render(IAPP_COMMAND, ['chain select bellecour'], {
cwd: join(testDir, projectName),
});
await retry(
async () => {
const config = await readIAppConfig(join(testDir, projectName));
assert.strictEqual(config.defaultChain, 'bellecour');
},
{
retries: 10,
delay: 100,
}
);
});

test('select arbitrum-sepolia-testnet works', async () => {
await render(IAPP_COMMAND, ['chain select arbitrum-sepolia-testnet'], {
cwd: join(testDir, projectName),
});
await retry(
async () => {
const config = await readIAppConfig(join(testDir, projectName));
assert.strictEqual(config.defaultChain, 'arbitrum-sepolia-testnet');
},
{
retries: 10,
delay: 100,
}
);
});

test('select arbitrum-mainnet works', async () => {
await render(IAPP_COMMAND, ['chain select arbitrum-mainnet'], {
cwd: join(testDir, projectName),
});
await retry(
async () => {
const config = await readIAppConfig(join(testDir, projectName));
assert.strictEqual(config.defaultChain, 'arbitrum-mainnet');
},
{
retries: 10,
delay: 100,
}
);
});
});

describe('JavaScript iApp', () => {
Expand All @@ -99,10 +178,13 @@ describe('JavaScript iApp', () => {
});

test('iapp test command works', async () => {
const { findByText, debug, clear, userEvent, getStdallStr } =
await render(IAPP_COMMAND, ['test'], {
const { findByText, clear, userEvent, getStdallStr } = await render(
IAPP_COMMAND,
['test'],
{
cwd: join(testDir, projectName),
});
}
);
// wait for docker build and test run
await retry(() => findByText('Would you like to see the app logs?'), {
retries: 8,
Expand All @@ -115,16 +197,12 @@ describe('JavaScript iApp', () => {
);
assert.ok(dockerImageIdMatch, 'Docker image ID not found in output');
const dockerImageId = dockerImageIdMatch![0].split('(')[1].slice(0, -1);

// debug();
clear();
userEvent.keyboard('n');
await findByText('Would you like to see the result?');
// debug();
clear();
userEvent.keyboard('n');
await findByText('When ready run iapp deploy');
// debug();
clear();

// check built docker image content
Expand Down Expand Up @@ -156,21 +234,24 @@ describe('JavaScript iApp', () => {
});

test('iapp test command works', async () => {
const { findByText, debug, clear, userEvent, getStdallStr } =
await render(IAPP_COMMAND, ['test'], {
const { findByText, clear, userEvent, getStdallStr } = await render(
IAPP_COMMAND,
['test'],
{
cwd: join(testDir, projectName),
});
}
);
await findByText('Do you want to attach an app secret to your iApp?');
userEvent.keyboard('y');
// debug()
// )
clear();
await findByText('What is the app secret?');
userEvent.keyboard('mySuperSecretAppSecret[Enter]');
// debug()
// )
clear();
await findByText('Do you want to save this app secret to your config?');
userEvent.keyboard('y');
// debug()
// )
clear();
// wait for docker build and test run
await retry(() => findByText('Would you like to see the app logs?'), {
Expand All @@ -184,16 +265,12 @@ describe('JavaScript iApp', () => {
);
assert.ok(dockerImageIdMatch, 'Docker image ID not found in output');
const dockerImageId = dockerImageIdMatch![0].split('(')[1].slice(0, -1);

// debug();
clear();
userEvent.keyboard('n');
await findByText('Would you like to see the result?');
// debug();
clear();
userEvent.keyboard('n');
await findByText('When ready run iapp deploy');
// debug();
clear();

// check built docker image content
Expand Down Expand Up @@ -227,10 +304,13 @@ describe('Python iApp', () => {
});

test('iapp test command works', async () => {
const { findByText, debug, clear, userEvent, getStdallStr } =
await render(IAPP_COMMAND, ['test'], {
const { findByText, clear, userEvent, getStdallStr } = await render(
IAPP_COMMAND,
['test'],
{
cwd: join(testDir, projectName),
});
}
);
// wait for docker build and test run
await retry(() => findByText('Would you like to see the app logs?'), {
retries: 8,
Expand All @@ -243,16 +323,12 @@ describe('Python iApp', () => {
);
assert.ok(dockerImageIdMatch, 'Docker image ID not found in output');
const dockerImageId = dockerImageIdMatch![0].split('(')[1].slice(0, -1);

// debug();
clear();
userEvent.keyboard('n');
await findByText('Would you like to see the result?');
// debug();
clear();
userEvent.keyboard('n');
await findByText('When ready run iapp deploy');
// debug();
clear();

// check built docker image content
Expand All @@ -279,21 +355,24 @@ describe('Python iApp', () => {
});

test('iapp test command works', async () => {
const { findByText, debug, clear, userEvent, getStdallStr } =
await render(IAPP_COMMAND, ['test'], {
const { findByText, clear, userEvent, getStdallStr } = await render(
IAPP_COMMAND,
['test'],
{
cwd: join(testDir, projectName),
});
}
);
await findByText('Do you want to attach an app secret to your iApp?');
userEvent.keyboard('y');
// debug()
// )
clear();
await findByText('What is the app secret?');
userEvent.keyboard('mySuperSecretAppSecret[Enter]');
// debug()
// )
clear();
await findByText('Do you want to save this app secret to your config?');
userEvent.keyboard('y');
// debug()
// )
clear();
// wait for docker build and test run
await retry(() => findByText('Would you like to see the app logs?'), {
Expand All @@ -307,16 +386,12 @@ describe('Python iApp', () => {
);
assert.ok(dockerImageIdMatch, 'Docker image ID not found in output');
const dockerImageId = dockerImageIdMatch![0].split('(')[1].slice(0, -1);

// debug();
clear();
userEvent.keyboard('n');
await findByText('Would you like to see the result?');
// debug();
clear();
userEvent.keyboard('n');
await findByText('When ready run iapp deploy');
// debug();
clear();

// check built docker image content
Expand Down Expand Up @@ -361,10 +436,13 @@ describe('Custom app', () => {
'utf-8'
);

const { findByText, debug, clear, userEvent, getStdallStr } =
await render(IAPP_COMMAND, ['test'], {
const { findByText, clear, userEvent, getStdallStr } = await render(
IAPP_COMMAND,
['test'],
{
cwd: join(testDir, projectName),
});
}
);
// wait for docker build and test run
await retry(() => findByText('Would you like to see the app logs?'), {
retries: 8,
Expand All @@ -377,16 +455,12 @@ describe('Custom app', () => {
);
assert.ok(dockerImageIdMatch, 'Docker image ID not found in output');
const dockerImageId = dockerImageIdMatch![0].split('(')[1].slice(0, -1);

// debug();
clear();
userEvent.keyboard('n');
await findByText('Would you like to see the result?');
// debug();
clear();
userEvent.keyboard('n');
await findByText('When ready run iapp deploy');
// debug();
clear();

// check built docker image content
Expand Down
Loading