2024-01-25 05:24:05 +00:00
|
|
|
import fs from 'fs';
|
2024-01-24 13:26:35 +00:00
|
|
|
import assert from 'assert';
|
2024-01-25 09:52:38 +00:00
|
|
|
import { spawnSync } from 'child_process';
|
|
|
|
|
|
|
|
import {
|
|
|
|
CHAIN_ID,
|
|
|
|
TOKEN_TYPE,
|
|
|
|
COMMIT_DURATION,
|
2024-01-25 10:17:24 +00:00
|
|
|
REVEAL_DURATION,
|
2024-01-25 09:52:38 +00:00
|
|
|
delay,
|
|
|
|
checkResultAndRetrieveOutput,
|
|
|
|
createBond,
|
|
|
|
getBondObj,
|
|
|
|
getAccountObj,
|
|
|
|
getRecordObj,
|
|
|
|
getAuthorityObj,
|
|
|
|
getAuctionObj,
|
|
|
|
getBidObject
|
|
|
|
} from './helpers';
|
2024-01-25 04:26:33 +00:00
|
|
|
|
2024-01-24 06:51:43 +00:00
|
|
|
describe('Test laconic CLI commands', () => {
|
|
|
|
test('laconic', async () => {
|
|
|
|
const result = spawnSync('laconic');
|
2024-01-25 06:56:49 +00:00
|
|
|
expect(result.status).toBe(1);
|
2024-01-24 06:51:43 +00:00
|
|
|
|
|
|
|
const output = result.stdout.toString().trim();
|
|
|
|
const errorOutput = result.stderr.toString().trim();
|
|
|
|
|
|
|
|
// Expect error with usage string
|
|
|
|
expect(output).toBe('');
|
|
|
|
expect(errorOutput).toContain('laconic <command>');
|
|
|
|
});
|
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
test('laconic cns', async () => {
|
|
|
|
const result = spawnSync('laconic', ['cns']);
|
2024-01-25 06:56:49 +00:00
|
|
|
expect(result.status).toBe(1);
|
2024-01-25 04:26:33 +00:00
|
|
|
|
|
|
|
const output = result.stdout.toString().trim();
|
|
|
|
const errorOutput = result.stderr.toString().trim();
|
|
|
|
|
|
|
|
// Expect error with usage string
|
|
|
|
expect(output).toBe('');
|
|
|
|
expect(errorOutput).toContain('laconic cns');
|
|
|
|
expect(errorOutput).toContain('CNS tools');
|
|
|
|
expect(errorOutput).toContain('Commands:');
|
|
|
|
});
|
|
|
|
|
2024-01-25 08:40:35 +00:00
|
|
|
// TODO: Add tests for CNS commands with all available flags
|
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
describe('laconic CNS commands', () => {
|
|
|
|
const initialAccountBalance = Number('100000000000000000000000000');
|
2024-01-25 06:56:49 +00:00
|
|
|
const testAccount = process.env.TEST_ACCOUNT;
|
|
|
|
const testAccount2 = 'ethm1vc62ysqu504at932jjq8pwrqgjt67rx6ggn5yu';
|
|
|
|
assert(testAccount, 'TEST_ACCOUNT not set in env');
|
2024-01-25 04:26:33 +00:00
|
|
|
|
2024-01-25 09:52:38 +00:00
|
|
|
const testAuthorityName = 'laconic';
|
|
|
|
let testAuctionId: string;
|
2024-01-25 10:48:19 +00:00
|
|
|
const testRecordFilePath = 'test/data/watcher-record.yml';
|
|
|
|
let testRecordId: string, testRecordBondId: string;
|
2024-01-25 09:52:38 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
test('laconic cns status', async () => {
|
|
|
|
const result = spawnSync('laconic', ['cns', 'status']);
|
2024-01-25 07:15:30 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
2024-01-24 07:17:38 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
// Expect output object to have CNS status props
|
|
|
|
expect(outputObj).toHaveProperty('version');
|
|
|
|
expect(outputObj).toHaveProperty('node');
|
2024-01-25 09:52:38 +00:00
|
|
|
expect(outputObj).toHaveProperty('node.network', CHAIN_ID);
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(outputObj).toHaveProperty('sync');
|
|
|
|
expect(Number(outputObj.sync.latest_block_height)).toBeGreaterThan(0);
|
|
|
|
expect(outputObj).toHaveProperty('validator');
|
|
|
|
expect(outputObj).toHaveProperty('validators');
|
|
|
|
expect(outputObj).toHaveProperty('num_peers');
|
|
|
|
expect(outputObj).toHaveProperty('peers');
|
|
|
|
expect(outputObj).toHaveProperty('disk_usage');
|
2024-01-24 07:17:38 +00:00
|
|
|
});
|
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
describe('Bond operations', () => {
|
2024-01-25 11:14:42 +00:00
|
|
|
let bondBalance = 1000000000;
|
2024-01-25 06:56:49 +00:00
|
|
|
const bondOwner = testAccount;
|
2024-01-25 05:24:05 +00:00
|
|
|
let bondId: string;
|
2024-01-24 13:26:35 +00:00
|
|
|
|
2024-01-25 11:35:21 +00:00
|
|
|
test('laconic cns bond create --type <type> --quantity <quantity> --gas <gas> --fees <fees>', async () => {
|
2024-01-25 04:26:33 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondBalance.toString(), '--gas', '200000', '--fees', `200000${TOKEN_TYPE}`]);
|
2024-01-25 07:15:30 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
2024-01-25 04:26:33 +00:00
|
|
|
|
2024-01-25 06:11:00 +00:00
|
|
|
// Expect output object to have resultant bond id
|
2024-01-25 09:52:38 +00:00
|
|
|
expect(outputObj.bondId).toBeDefined();
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
bondId = outputObj.bondId;
|
|
|
|
});
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
test('laconic cns bond list', async () => {
|
|
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'list']);
|
2024-01-25 07:15:30 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
// Expected bond
|
2024-01-25 06:56:49 +00:00
|
|
|
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toEqual(expectedBond);
|
|
|
|
});
|
2024-01-24 09:02:12 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
test('laconic cns bond list --owner <owner_address>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'list', '--owner', bondOwner]);
|
2024-01-25 07:15:30 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
// Expected bond
|
2024-01-25 06:56:49 +00:00
|
|
|
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toEqual(expectedBond);
|
|
|
|
});
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
test('laconic cns bond get --id <bond_id>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'get', '--id', bondId]);
|
2024-01-25 07:15:30 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
// Expected bond
|
2024-01-25 06:56:49 +00:00
|
|
|
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toEqual(expectedBond);
|
|
|
|
});
|
2024-01-25 08:40:35 +00:00
|
|
|
|
2024-01-25 11:14:42 +00:00
|
|
|
test('laconic cns bond refill --id <bond_id> --type <type> --quantity <quantity>', async () => {
|
|
|
|
const bondRefillAmount = 1000;
|
|
|
|
bondBalance += bondRefillAmount;
|
|
|
|
|
|
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'refill', '--id', bondId, '--type', TOKEN_TYPE, '--quantity', bondRefillAmount.toString()]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
// Check updated bond
|
|
|
|
const bondResult = spawnSync('laconic', ['cns', 'bond', 'get', '--id', bondId]);
|
|
|
|
const bondOutputObj = checkResultAndRetrieveOutput(bondResult);
|
|
|
|
|
|
|
|
// Expected bond
|
|
|
|
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
|
|
|
|
|
|
|
|
expect(bondOutputObj.length).toEqual(1);
|
|
|
|
expect(bondOutputObj[0]).toEqual(expectedBond);
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic cns bond withdraw --id <bond_id> --type <type> --quantity <quantity>', async () => {
|
2024-01-25 11:14:42 +00:00
|
|
|
const bondWithdrawAmount = 500;
|
|
|
|
bondBalance -= bondWithdrawAmount;
|
|
|
|
|
|
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'withdraw', '--id', bondId, '--type', TOKEN_TYPE, '--quantity', bondWithdrawAmount.toString()]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
// Check updated bond
|
|
|
|
const bondResult = spawnSync('laconic', ['cns', 'bond', 'get', '--id', bondId]);
|
|
|
|
const bondOutputObj = checkResultAndRetrieveOutput(bondResult);
|
|
|
|
|
|
|
|
// Expected bond
|
|
|
|
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
|
|
|
|
|
|
|
|
// Expect balance to be deducted (also deducts gas)
|
|
|
|
expect(bondOutputObj.length).toEqual(1);
|
|
|
|
expect(bondOutputObj[0]).toEqual(expectedBond);
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic cns bond cancel --id <bond_id>', async () => {
|
2024-01-25 11:14:42 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'cancel', '--id', bondId]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
// Check updated bond
|
|
|
|
const bondResult = spawnSync('laconic', ['cns', 'bond', 'get', '--id', bondId]);
|
|
|
|
const bondOutputObj = checkResultAndRetrieveOutput(bondResult);
|
|
|
|
|
|
|
|
// Expect empty object
|
|
|
|
expect(bondOutputObj.length).toEqual(1);
|
|
|
|
expect(bondOutputObj[0]).toEqual({ id: '', owner: '', balance: [] });
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
2024-01-25 04:26:33 +00:00
|
|
|
});
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
describe('Account and tokens operations', () => {
|
|
|
|
let balanceBeforeSend: number;
|
2024-01-24 12:52:03 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
test('laconic cns account get --address <account_address>', async () => {
|
2024-01-25 06:56:49 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'account', 'get', '--address', testAccount]);
|
2024-01-25 07:15:30 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
2024-01-25 04:26:33 +00:00
|
|
|
|
|
|
|
// Expected account
|
2024-01-25 12:06:26 +00:00
|
|
|
const expectedAccount = getAccountObj({ address: testAccount });
|
2024-01-25 04:26:33 +00:00
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toMatchObject(expectedAccount);
|
2024-01-25 09:52:38 +00:00
|
|
|
expect(outputObj[0].number).toBeDefined();
|
|
|
|
expect(outputObj[0].sequence).toBeDefined();
|
2024-01-25 06:56:49 +00:00
|
|
|
|
|
|
|
balanceBeforeSend = Number(outputObj[0].balance[0].quantity);
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(balanceBeforeSend).toBeGreaterThan(0);
|
|
|
|
expect(balanceBeforeSend).toBeLessThan(initialAccountBalance);
|
2024-01-24 09:02:12 +00:00
|
|
|
});
|
2024-01-24 13:40:49 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
test('laconic cns tokens send --address <account_address> --type <token_type> --quantity <quantity>', async () => {
|
|
|
|
const sendAmount = 1000000000;
|
|
|
|
const balanceAfterSend = balanceBeforeSend - sendAmount;
|
2024-01-24 13:40:49 +00:00
|
|
|
|
2024-01-25 06:56:49 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'tokens', 'send', '--address', testAccount2, '--type', TOKEN_TYPE, '--quantity', sendAmount.toString()]);
|
2024-01-25 07:15:30 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
2024-01-24 13:40:49 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
// Expected acconts
|
|
|
|
const expectedAccounts = [
|
2024-01-25 06:56:49 +00:00
|
|
|
getAccountObj({ address: testAccount, balance: balanceAfterSend }),
|
2024-01-25 12:06:26 +00:00
|
|
|
getAccountObj({ address: testAccount2, balance: sendAmount })
|
2024-01-25 04:26:33 +00:00
|
|
|
];
|
2024-01-24 13:40:49 +00:00
|
|
|
|
2024-01-25 04:26:33 +00:00
|
|
|
expect(outputObj.length).toEqual(2);
|
|
|
|
expect(outputObj).toMatchObject(expectedAccounts);
|
2024-01-24 13:40:49 +00:00
|
|
|
});
|
2024-01-24 07:17:38 +00:00
|
|
|
});
|
2024-01-25 05:24:05 +00:00
|
|
|
|
|
|
|
describe('Record operations', () => {
|
|
|
|
const gas = 250000;
|
|
|
|
const bondBalance = 1000000000;
|
|
|
|
|
|
|
|
test('laconic cns record publish --filename <record_file> --bond-id <bond_id> --gas <gas>', async () => {
|
2024-01-25 06:56:49 +00:00
|
|
|
// Create a new bond to be associated with the record
|
2024-01-25 10:48:19 +00:00
|
|
|
({ bondId: testRecordBondId } = createBond(bondBalance));
|
2024-01-25 06:56:49 +00:00
|
|
|
|
2024-01-25 10:48:19 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'record', 'publish', '--filename', testRecordFilePath, '--bond-id', testRecordBondId, '--gas', gas.toString()]);
|
2024-01-25 07:15:30 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
2024-01-25 05:24:05 +00:00
|
|
|
|
|
|
|
// Expect output object to resultant bond id
|
2024-01-25 09:52:38 +00:00
|
|
|
expect(outputObj.id).toBeDefined();
|
2024-01-25 05:24:05 +00:00
|
|
|
|
2024-01-25 10:48:19 +00:00
|
|
|
testRecordId = outputObj.id;
|
2024-01-25 05:24:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic cns record list', async () => {
|
|
|
|
const result = spawnSync('laconic', ['cns', 'record', 'list']);
|
2024-01-25 07:15:30 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
2024-01-25 05:24:05 +00:00
|
|
|
|
|
|
|
// Expected record
|
2024-01-25 10:48:19 +00:00
|
|
|
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: null });
|
2024-01-25 05:24:05 +00:00
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toMatchObject(expectedRecord);
|
2024-01-25 09:52:38 +00:00
|
|
|
expect(outputObj[0].createTime).toBeDefined();
|
|
|
|
expect(outputObj[0].expiryTime).toBeDefined();
|
|
|
|
expect(outputObj[0].owners).toBeDefined();
|
2024-01-25 05:24:05 +00:00
|
|
|
expect(outputObj[0].owners.length).toEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic cns record get --id <record_id>', async () => {
|
2024-01-25 10:48:19 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'record', 'get', '--id', testRecordId]);
|
2024-01-25 07:15:30 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
2024-01-25 05:24:05 +00:00
|
|
|
|
|
|
|
// Expected record
|
2024-01-25 10:48:19 +00:00
|
|
|
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: null });
|
2024-01-25 05:24:05 +00:00
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toMatchObject(expectedRecord);
|
|
|
|
});
|
2024-01-25 08:40:35 +00:00
|
|
|
|
|
|
|
describe('Bond records operations', () => {
|
2024-01-25 11:35:21 +00:00
|
|
|
let testRecordBondId2: string;
|
2024-01-25 08:40:35 +00:00
|
|
|
|
|
|
|
test('laconic cns bond dissociate --id <record_id>', async () => {
|
2024-01-25 11:35:21 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'dissociate', '--id', testRecordId]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
const recordResult = spawnSync('laconic', ['cns', 'record', 'get', '--id', testRecordId]);
|
|
|
|
const recordOutputObj = checkResultAndRetrieveOutput(recordResult);
|
|
|
|
|
|
|
|
// Expected record
|
|
|
|
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: '', recordId: testRecordId, names: null });
|
|
|
|
|
|
|
|
expect(recordOutputObj.length).toEqual(1);
|
|
|
|
expect(recordOutputObj[0]).toMatchObject(expectedRecord);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic cns bond associate --id <record_id> --bond-id <bond_id>', async () => {
|
|
|
|
// Create a new bond to be associated with the record
|
|
|
|
({ bondId: testRecordBondId2 } = createBond(bondBalance));
|
|
|
|
|
|
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'associate', '--id', testRecordId, '--bond-id', testRecordBondId2]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
const recordResult = spawnSync('laconic', ['cns', 'record', 'get', '--id', testRecordId]);
|
|
|
|
const recordOutputObj = checkResultAndRetrieveOutput(recordResult);
|
|
|
|
|
|
|
|
// Expected record
|
|
|
|
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId2, recordId: testRecordId, names: null });
|
|
|
|
|
|
|
|
expect(recordOutputObj.length).toEqual(1);
|
|
|
|
expect(recordOutputObj[0]).toMatchObject(expectedRecord);
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic cns bond records reassociate --old-bond-id <old_bond_id> --new-bond-id <new_bond_id>', async () => {
|
2024-01-25 11:35:21 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'bond', 'records', 'reassociate', '--old-bond-id', testRecordBondId2, '--new-bond-id', testRecordBondId]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
const recordResult = spawnSync('laconic', ['cns', 'record', 'get', '--id', testRecordId]);
|
|
|
|
const recordOutputObj = checkResultAndRetrieveOutput(recordResult);
|
|
|
|
|
|
|
|
// Expected record
|
|
|
|
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: null });
|
|
|
|
|
|
|
|
expect(recordOutputObj.length).toEqual(1);
|
|
|
|
expect(recordOutputObj[0]).toMatchObject(expectedRecord);
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
|
|
|
});
|
2024-01-25 05:24:05 +00:00
|
|
|
});
|
2024-01-25 06:11:00 +00:00
|
|
|
|
2024-01-25 08:40:35 +00:00
|
|
|
describe('Name authority operations (pre auction)', () => {
|
2024-01-25 06:11:00 +00:00
|
|
|
test('laconic cns authority reserve <authority_name>', async () => {
|
2024-01-25 09:52:38 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'authority', 'reserve', testAuthorityName]);
|
2024-01-25 07:15:30 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
2024-01-25 06:11:00 +00:00
|
|
|
|
|
|
|
// Expect result
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic cns authority whois <authority_name>', async () => {
|
2024-01-25 09:52:38 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'authority', 'whois', testAuthorityName]);
|
2024-01-25 07:15:30 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
2024-01-25 06:11:00 +00:00
|
|
|
|
|
|
|
// Expected authority (still in auction)
|
2024-01-25 10:17:24 +00:00
|
|
|
const expectedAuthority = getAuthorityObj({ owner: '', status: 'auction', auction: getAuctionObj({ owner: testAccount }) });
|
2024-01-25 06:11:00 +00:00
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toMatchObject(expectedAuthority);
|
2024-01-25 09:52:38 +00:00
|
|
|
expect(outputObj[0].expiryTime).toBeDefined();
|
2024-01-25 06:11:00 +00:00
|
|
|
expect(outputObj[0].height).toBeGreaterThan(0);
|
2024-01-25 09:52:38 +00:00
|
|
|
|
|
|
|
testAuctionId = outputObj[0].auction.id;
|
2024-01-25 06:11:00 +00:00
|
|
|
});
|
|
|
|
});
|
2024-01-25 08:40:35 +00:00
|
|
|
|
|
|
|
describe('Auction operations', () => {
|
2024-01-25 09:52:38 +00:00
|
|
|
const bidAmount = 25000000;
|
|
|
|
let bidRevealFilePath: string;
|
|
|
|
|
2024-01-25 08:40:35 +00:00
|
|
|
test('laconic cns auction get <auction_id>', async () => {
|
2024-01-25 09:52:38 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'auction', 'get', testAuctionId]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected auction (still in commit stage)
|
|
|
|
const expectedAuction = getAuctionObj({ owner: testAccount, status: 'commit' });
|
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toMatchObject(expectedAuction);
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic cns auction bid commit <auction_id> <quantity> <type>', async () => {
|
2024-01-25 09:52:38 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'auction', 'bid', 'commit', testAuctionId, bidAmount.toString(), TOKEN_TYPE]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
2024-01-25 08:40:35 +00:00
|
|
|
|
2024-01-25 09:52:38 +00:00
|
|
|
// Expected output
|
|
|
|
expect(outputObj.reveal_file).toBeDefined();
|
|
|
|
|
|
|
|
bidRevealFilePath = outputObj.reveal_file;
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
2024-01-25 09:52:38 +00:00
|
|
|
|
|
|
|
test('laconic cns auction bid reveal <auction_id> <file_path>', async () => {
|
2024-01-25 10:17:24 +00:00
|
|
|
// Wait for auction commits duration (60s)
|
2024-01-25 09:52:38 +00:00
|
|
|
await delay(COMMIT_DURATION * 1000);
|
|
|
|
|
|
|
|
const auctionResult = spawnSync('laconic', ['cns', 'auction', 'get', testAuctionId]);
|
|
|
|
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
|
|
|
|
|
|
const expectedAuction = getAuctionObj({ owner: testAccount, status: 'reveal' });
|
|
|
|
const expectedBid = getBidObject({ bidder: testAccount });
|
|
|
|
|
|
|
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuction);
|
|
|
|
expect(auctionOutputObj[0].bids[0]).toMatchObject(expectedBid);
|
|
|
|
|
|
|
|
// Reveal bid
|
|
|
|
const result = spawnSync('laconic', ['cns', 'auction', 'bid', 'reveal', testAuctionId, bidRevealFilePath]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
const revealObject = JSON.parse(fs.readFileSync(bidRevealFilePath, 'utf8'));
|
|
|
|
expect(revealObject).toMatchObject({
|
|
|
|
chainId: CHAIN_ID,
|
|
|
|
auctionId: testAuctionId,
|
|
|
|
bidderAddress: testAccount,
|
|
|
|
bidAmount: `${bidAmount}aphoton`
|
|
|
|
});
|
|
|
|
}, (COMMIT_DURATION + 5) * 1000);
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Name authority operations (post auction)', () => {
|
2024-01-25 10:17:24 +00:00
|
|
|
const testSubAuthorityName = 'echo.laconic';
|
|
|
|
const testSubAuthorityName2 = 'kube.laconic';
|
|
|
|
|
|
|
|
test('laconic cns authority whois <authority_name>', async () => {
|
|
|
|
// Wait for auction reveals duration (60s)
|
|
|
|
await delay(REVEAL_DURATION * 1000);
|
|
|
|
|
|
|
|
const result = spawnSync('laconic', ['cns', 'authority', 'whois', testAuthorityName]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected authority (active)
|
|
|
|
const expectedAuthority = getAuthorityObj({ owner: testAccount, status: 'active', auction: null });
|
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toMatchObject(expectedAuthority);
|
|
|
|
}, (REVEAL_DURATION + 5) * 1000);
|
|
|
|
|
2024-01-25 08:40:35 +00:00
|
|
|
test('laconic cns authority bond set laconic <bond_id>', async () => {
|
2024-01-25 10:17:24 +00:00
|
|
|
// Create a new bond to be set on the authority
|
|
|
|
const bondBalance = 1000000000;
|
|
|
|
const { bondId } = createBond(bondBalance);
|
|
|
|
|
|
|
|
const result = spawnSync('laconic', ['cns', 'authority', 'bond', 'set', testAuthorityName, bondId]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
// Check updated authority
|
|
|
|
const authorityResult = spawnSync('laconic', ['cns', 'authority', 'whois', testAuthorityName]);
|
|
|
|
const authorityOutputObj = checkResultAndRetrieveOutput(authorityResult);
|
|
|
|
|
|
|
|
// Expected authority (active with bond)
|
|
|
|
const expectedAuthority = getAuthorityObj({ owner: testAccount, status: 'active', auction: null, bondId: bondId });
|
|
|
|
|
|
|
|
expect(authorityOutputObj.length).toEqual(1);
|
|
|
|
expect(authorityOutputObj[0]).toMatchObject(expectedAuthority);
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic cns authority reserve <sub_authority> (same owner)', async () => {
|
2024-01-25 10:17:24 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'authority', 'reserve', testSubAuthorityName]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
// Check updated authority
|
|
|
|
const authorityResult = spawnSync('laconic', ['cns', 'authority', 'whois', testSubAuthorityName]);
|
|
|
|
const authorityOutputObj = checkResultAndRetrieveOutput(authorityResult);
|
|
|
|
|
|
|
|
// Expected authority (active with bond)
|
|
|
|
const expectedAuthority = getAuthorityObj({ owner: testAccount, status: 'active', auction: null });
|
|
|
|
|
|
|
|
expect(authorityOutputObj.length).toEqual(1);
|
|
|
|
expect(authorityOutputObj[0]).toMatchObject(expectedAuthority);
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic cns authority reserve <sub_authority> --owner <owner_address> (different owner)', async () => {
|
2024-01-25 10:17:24 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'authority', 'reserve', testSubAuthorityName2, '--owner', testAccount2]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
// Check updated authority
|
|
|
|
const authorityResult = spawnSync('laconic', ['cns', 'authority', 'whois', testSubAuthorityName2]);
|
|
|
|
const authorityOutputObj = checkResultAndRetrieveOutput(authorityResult);
|
|
|
|
|
|
|
|
// Expected authority (active with bond)
|
|
|
|
const expectedAuthority = getAuthorityObj({ owner: testAccount2, status: 'active', auction: null });
|
|
|
|
|
|
|
|
expect(authorityOutputObj.length).toEqual(1);
|
|
|
|
expect(authorityOutputObj[0]).toMatchObject(expectedAuthority);
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Name operations', () => {
|
2024-01-25 10:48:19 +00:00
|
|
|
const testName = 'crn://laconic/watcher/erc20';
|
|
|
|
|
2024-01-25 08:40:35 +00:00
|
|
|
test('laconic cns name set <name> <record_id>', async () => {
|
2024-01-25 10:48:19 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'name', 'set', testName, testRecordId]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic cns name lookup <name>', async () => {
|
2024-01-25 10:48:19 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'name', 'lookup', testName]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toMatchObject({ latest: { id: testRecordId } });
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic cns name resolve <name>', async () => {
|
2024-01-25 10:48:19 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'name', 'resolve', testName]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected resolved record
|
|
|
|
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: [testName] });
|
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toMatchObject(expectedRecord);
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic cns name delete <name>', async () => {
|
2024-01-25 10:48:19 +00:00
|
|
|
const result = spawnSync('laconic', ['cns', 'name', 'delete', testName]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
// Check that name doesn't resolve
|
|
|
|
const resolveResult = spawnSync('laconic', ['cns', 'name', 'resolve', testName]);
|
|
|
|
const resolveOutputObj = checkResultAndRetrieveOutput(resolveResult);
|
|
|
|
expect(resolveOutputObj.length).toEqual(0);
|
2024-01-25 08:40:35 +00:00
|
|
|
});
|
|
|
|
});
|
2024-01-24 06:51:43 +00:00
|
|
|
});
|
|
|
|
});
|