Add CLI tests and setup CI #53
@ -1,3 +1,4 @@
|
|||||||
|
import assert from 'assert';
|
||||||
import { spawnSync } from 'child_process';
|
import { spawnSync } from 'child_process';
|
||||||
|
|
||||||
describe('Test laconic CLI commands', () => {
|
describe('Test laconic CLI commands', () => {
|
||||||
@ -30,6 +31,9 @@ describe('Test laconic CLI commands', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('laconic cns <command>', () => {
|
describe('laconic cns <command>', () => {
|
||||||
|
const existingAccount = process.env.EXISTING_ACCOUNT;
|
||||||
|
assert(existingAccount, 'EXISTING_ACCOUNT not set in env');
|
||||||
|
|
||||||
test('laconic cns status', async () => {
|
test('laconic cns status', async () => {
|
||||||
const result = spawnSync('laconic', ['cns', 'status']);
|
const result = spawnSync('laconic', ['cns', 'status']);
|
||||||
|
|
||||||
@ -55,8 +59,8 @@ describe('Test laconic CLI commands', () => {
|
|||||||
|
|
||||||
describe('laconic cns bond <command>', () => {
|
describe('laconic cns bond <command>', () => {
|
||||||
const bondBalance = 1000000000;
|
const bondBalance = 1000000000;
|
||||||
|
const bondOwner = existingAccount;
|
||||||
let bondId: string;
|
let bondId: string;
|
||||||
let bondOwner: string;
|
|
||||||
|
|
||||||
test('laconic cns bond create', async () => {
|
test('laconic cns bond create', async () => {
|
||||||
const result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', 'aphoton', '--quantity', bondBalance.toString(), '--gas', '200000', '--fees', '200000aphoton']);
|
const result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', 'aphoton', '--quantity', bondBalance.toString(), '--gas', '200000', '--fees', '200000aphoton']);
|
||||||
@ -89,13 +93,10 @@ describe('Test laconic CLI commands', () => {
|
|||||||
const outputObj = Array.from<any>(JSON.parse(output));
|
const outputObj = Array.from<any>(JSON.parse(output));
|
||||||
|
|
||||||
// Expected bond
|
// Expected bond
|
||||||
const expectedBond = getExpectedBond({ id: bondId, balance: bondBalance });
|
const expectedBond = getExpectedBond({ id: bondId, owner: bondOwner, balance: bondBalance });
|
||||||
|
|
||||||
expect(outputObj.length).toEqual(1);
|
expect(outputObj.length).toEqual(1);
|
||||||
expect(outputObj[0]).toHaveProperty('owner');
|
expect(outputObj[0]).toEqual(expectedBond);
|
||||||
expect(outputObj[0]).toMatchObject(expectedBond);
|
|
||||||
|
|
||||||
bondOwner = outputObj[0].owner;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('laconic cns bond list --owner <owner_address>', async () => {
|
test('laconic cns bond list --owner <owner_address>', async () => {
|
||||||
@ -142,9 +143,10 @@ describe('Test laconic CLI commands', () => {
|
|||||||
|
|
||||||
// Helper methods
|
// Helper methods
|
||||||
|
|
||||||
function getExpectedBond(params: { id: string, balance: number, owner?: string }): any {
|
function getExpectedBond(params: { id: string, owner: string, balance: number}): any {
|
||||||
const bond: any = {
|
return {
|
||||||
id: params.id,
|
id: params.id,
|
||||||
|
owner: params.owner,
|
||||||
balance: [
|
balance: [
|
||||||
{
|
{
|
||||||
type: "aphoton",
|
type: "aphoton",
|
||||||
@ -152,11 +154,4 @@ function getExpectedBond(params: { id: string, balance: number, owner?: string }
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add owner only if passed
|
|
||||||
if (params.owner) {
|
|
||||||
bond.owner = params.owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
return bond;
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
# Get the key from laconicd
|
# Get the key from laconicd
|
||||||
laconicd_key=$(yes | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe)
|
laconicd_key=$(yes | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe)
|
||||||
|
|
||||||
|
# Get the fixturenet account address
|
||||||
|
laconicd_account_address=$(docker compose exec laconicd laconicd keys list | awk '/- address:/ {print $3}')
|
||||||
|
|
||||||
# Set parameters for the test suite
|
# Set parameters for the test suite
|
||||||
cosmos_chain_id=laconic_9000-1
|
cosmos_chain_id=laconic_9000-1
|
||||||
laconicd_rest_endpoint=http://127.0.0.1:1317
|
laconicd_rest_endpoint=http://127.0.0.1:1317
|
||||||
@ -26,4 +29,4 @@ echo "$config" > "$config_file"
|
|||||||
docker compose exec laconicd sh -c "curl --retry 10 --retry-delay 3 --retry-connrefused http://127.0.0.1:9473/api"
|
docker compose exec laconicd sh -c "curl --retry 10 --retry-delay 3 --retry-connrefused http://127.0.0.1:9473/api"
|
||||||
|
|
||||||
# Run tests
|
# Run tests
|
||||||
yarn test
|
EXISTING_ACCOUNT=$laconicd_account_address yarn test
|
||||||
|
Loading…
Reference in New Issue
Block a user