2024-01-29 04:46:32 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
import assert from 'assert';
|
|
|
|
import { spawnSync } from 'child_process';
|
|
|
|
|
2024-09-20 09:32:26 +00:00
|
|
|
import { AUCTION_KIND_PROVIDER, AUCTION_KIND_VICKREY } from '@cerc-io/registry-sdk';
|
2024-09-20 05:29:01 +00:00
|
|
|
|
2024-01-29 04:46:32 +00:00
|
|
|
import {
|
|
|
|
CHAIN_ID,
|
|
|
|
TOKEN_TYPE,
|
|
|
|
AUCTION_COMMIT_DURATION,
|
|
|
|
AUCTION_REVEAL_DURATION,
|
|
|
|
delay,
|
|
|
|
checkResultAndRetrieveOutput,
|
|
|
|
createBond,
|
|
|
|
getBondObj,
|
|
|
|
getAccountObj,
|
|
|
|
getRecordObj,
|
|
|
|
getAuthorityObj,
|
|
|
|
getAuctionObj,
|
2024-09-06 09:44:47 +00:00
|
|
|
getBidObj,
|
2024-09-20 05:29:01 +00:00
|
|
|
updateGasAndFeesConfig,
|
|
|
|
AUCTION_STATUS
|
2024-01-29 04:46:32 +00:00
|
|
|
} from './helpers';
|
|
|
|
|
|
|
|
describe('Test laconic CLI commands', () => {
|
|
|
|
test('laconic', async () => {
|
|
|
|
const result = spawnSync('laconic');
|
|
|
|
expect(result.status).toBe(1);
|
|
|
|
|
|
|
|
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-03-19 04:42:42 +00:00
|
|
|
test('laconic registry', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry']);
|
2024-01-29 04:46:32 +00:00
|
|
|
expect(result.status).toBe(1);
|
|
|
|
|
|
|
|
const output = result.stdout.toString().trim();
|
|
|
|
const errorOutput = result.stderr.toString().trim();
|
|
|
|
|
|
|
|
// Expect error with usage string
|
|
|
|
expect(output).toBe('');
|
2024-03-19 04:42:42 +00:00
|
|
|
expect(errorOutput).toContain('laconic registry');
|
|
|
|
expect(errorOutput).toContain('Registry tools');
|
2024-01-29 04:46:32 +00:00
|
|
|
expect(errorOutput).toContain('Commands:');
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO: Break up tests into separate files
|
2024-03-19 04:42:42 +00:00
|
|
|
// TODO: Add tests for registry commands with all available flags
|
2024-01-29 04:46:32 +00:00
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
describe('laconic registry commands', () => {
|
2024-01-29 04:46:32 +00:00
|
|
|
const testAccount = process.env.TEST_ACCOUNT;
|
|
|
|
assert(testAccount, 'TEST_ACCOUNT not set in env');
|
2024-03-18 13:58:52 +00:00
|
|
|
const testAccount2 = 'laconic1pmuxrcnuhhf8qdllzuf2ctj2tnwwcg6yswqnyd';
|
2024-07-30 13:24:46 +00:00
|
|
|
const initialAccountBalance = Number('1000000000000000000000000000000');
|
2024-01-29 04:46:32 +00:00
|
|
|
|
|
|
|
const testAuthorityName = 'laconic';
|
|
|
|
const testRecordFilePath = 'test/data/watcher-record.yml';
|
|
|
|
let testAuctionId: string, testRecordId: string, testRecordBondId: string;
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry status', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'status']);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
// Expect output object to have registry status props
|
2024-01-29 04:46:32 +00:00
|
|
|
expect(outputObj).toHaveProperty('version');
|
|
|
|
expect(outputObj).toHaveProperty('node');
|
|
|
|
expect(outputObj).toHaveProperty('node.network', CHAIN_ID);
|
|
|
|
expect(outputObj).toHaveProperty('sync');
|
2024-07-22 06:18:02 +00:00
|
|
|
expect(Number(outputObj.sync.latestBlockHeight)).toBeGreaterThan(0);
|
2024-01-29 04:46:32 +00:00
|
|
|
expect(outputObj).toHaveProperty('validator');
|
|
|
|
expect(outputObj).toHaveProperty('validators');
|
2024-07-22 06:18:02 +00:00
|
|
|
expect(outputObj).toHaveProperty('numPeers');
|
2024-01-29 04:46:32 +00:00
|
|
|
expect(outputObj).toHaveProperty('peers');
|
2024-07-22 06:18:02 +00:00
|
|
|
expect(outputObj).toHaveProperty('diskUsage');
|
2024-01-29 04:46:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Bond operations', () => {
|
|
|
|
const bondOwner = testAccount;
|
|
|
|
let bondBalance = 1000000000;
|
|
|
|
let bondId: string;
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry bond create --type <type> --quantity <quantity> --gas <gas> --fees <fees>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondBalance.toString(), '--gas', '200000', '--fees', `200000${TOKEN_TYPE}`]);
|
|
|
|
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expect output object to have resultant bond id
|
|
|
|
expect(outputObj.bondId).toBeDefined();
|
|
|
|
|
|
|
|
bondId = outputObj.bondId;
|
|
|
|
});
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry bond list', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'bond', 'list']);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected bond
|
|
|
|
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
|
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toEqual(expectedBond);
|
|
|
|
});
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry bond list --owner <owner_address>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'bond', 'list', '--owner', bondOwner]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected bond
|
|
|
|
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
|
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toEqual(expectedBond);
|
|
|
|
});
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry bond get --id <bond_id>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'bond', 'get', '--id', bondId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected bond
|
|
|
|
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
|
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toEqual(expectedBond);
|
|
|
|
});
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry bond refill --id <bond_id> --type <type> --quantity <quantity>', async () => {
|
2024-01-29 04:46:32 +00:00
|
|
|
const bondRefillAmount = 1000;
|
|
|
|
bondBalance += bondRefillAmount;
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
const result = spawnSync('laconic', ['registry', 'bond', 'refill', '--id', bondId, '--type', TOKEN_TYPE, '--quantity', bondRefillAmount.toString()]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
// Check updated bond
|
2024-03-19 04:42:42 +00:00
|
|
|
const bondResult = spawnSync('laconic', ['registry', 'bond', 'get', '--id', bondId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
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-03-19 04:42:42 +00:00
|
|
|
test('laconic registry bond withdraw --id <bond_id> --type <type> --quantity <quantity>', async () => {
|
2024-01-29 04:46:32 +00:00
|
|
|
const bondWithdrawAmount = 500;
|
|
|
|
bondBalance -= bondWithdrawAmount;
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
const result = spawnSync('laconic', ['registry', 'bond', 'withdraw', '--id', bondId, '--type', TOKEN_TYPE, '--quantity', bondWithdrawAmount.toString()]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
// Check updated bond
|
2024-03-19 04:42:42 +00:00
|
|
|
const bondResult = spawnSync('laconic', ['registry', 'bond', 'get', '--id', bondId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const bondOutputObj = checkResultAndRetrieveOutput(bondResult);
|
|
|
|
|
|
|
|
// Expected bond
|
|
|
|
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
|
|
|
|
|
|
|
|
// Expect balance to be deducted
|
|
|
|
expect(bondOutputObj.length).toEqual(1);
|
|
|
|
expect(bondOutputObj[0]).toEqual(expectedBond);
|
|
|
|
});
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry bond cancel --id <bond_id>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'bond', 'cancel', '--id', bondId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
// Check updated bond
|
2024-03-19 04:42:42 +00:00
|
|
|
const bondResult = spawnSync('laconic', ['registry', 'bond', 'get', '--id', bondId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const bondOutputObj = checkResultAndRetrieveOutput(bondResult);
|
|
|
|
|
|
|
|
// Expect empty object
|
|
|
|
expect(bondOutputObj.length).toEqual(1);
|
2024-03-18 13:58:52 +00:00
|
|
|
expect(bondOutputObj[0]).toEqual(null);
|
2024-01-29 04:46:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Account and tokens operations', () => {
|
|
|
|
let balanceBeforeSend: number;
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry account get --address <account_address>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'account', 'get', '--address', testAccount]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected account
|
2024-01-29 05:21:34 +00:00
|
|
|
const expectedAccount = getAccountObj({ address: testAccount });
|
2024-01-29 04:46:32 +00:00
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toMatchObject(expectedAccount);
|
|
|
|
expect(outputObj[0].number).toBeDefined();
|
|
|
|
expect(outputObj[0].sequence).toBeDefined();
|
|
|
|
|
|
|
|
balanceBeforeSend = Number(outputObj[0].balance[0].quantity);
|
|
|
|
expect(balanceBeforeSend).toBeGreaterThan(0);
|
|
|
|
expect(balanceBeforeSend).toBeLessThan(initialAccountBalance);
|
|
|
|
});
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry tokens send --address <account_address> --type <token_type> --quantity <quantity>', async () => {
|
2024-01-29 04:46:32 +00:00
|
|
|
const sendAmount = 1000000000;
|
|
|
|
const balanceAfterSend = balanceBeforeSend - sendAmount;
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
const result = spawnSync('laconic', ['registry', 'tokens', 'send', '--address', testAccount2, '--type', TOKEN_TYPE, '--quantity', sendAmount.toString()]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected acconts
|
|
|
|
const expectedAccounts = [
|
|
|
|
getAccountObj({ address: testAccount, balance: balanceAfterSend }),
|
2024-01-29 05:21:34 +00:00
|
|
|
getAccountObj({ address: testAccount2, balance: sendAmount })
|
2024-01-29 04:46:32 +00:00
|
|
|
];
|
|
|
|
|
927: Add gettx command and have send command return the tx hash. (#78)
To support https://git.vdb.to/cerc-io/stack-orchestrator/issues/927, add a new token command `gettx` to inspect a previous transaction, and adjust the output of `send` to include the tx details.
For example:
```
❯ laconic registry tokens send --address laconic1yqpc7cyfetpgmqtkk0ukevugeaau9p0cwmjlsu --type alnt --quantity 1000
{
"tx": {
"hash": "977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC",
"height": 343369,
"index": 0,
"code": 0,
"log": "",
"sender": "laconic14wc07wa3r7rppru43g9jxkzhqnhmvfm4dgey6s",
"recipient": "laconic1yqpc7cyfetpgmqtkk0ukevugeaau9p0cwmjlsu",
"amount": "1000alnt"
},
"accounts": [
{
"address": "laconic14wc07wa3r7rppru43g9jxkzhqnhmvfm4dgey6s",
"pubKey": "AvOh0Hdjj5/YKMTPEm/oLgvpg4gIP1vB4d1NhBMq6/+B",
"number": 3,
"sequence": 91,
"balance": [
{
"type": "alnt",
"quantity": 1.2899999999709944e+22
}
]
},
{
"address": "laconic1yqpc7cyfetpgmqtkk0ukevugeaau9p0cwmjlsu",
"pubKey": "A7XYVHLemQYUjXe6VnSDlcyzLnpdJ8CE8zvDiZtgxqnT",
"number": 1,
"sequence": 1,
"balance": [
{
"type": "alnt",
"quantity": 1.289999999991e+22
}
]
}
]
}
```
```
❯ laconic registry tokens gettx --hash 977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC
{
"hash": "977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC",
"height": 343369,
"index": 0,
"code": 0,
"log": "",
"sender": "laconic14wc07wa3r7rppru43g9jxkzhqnhmvfm4dgey6s",
"recipient": "laconic1yqpc7cyfetpgmqtkk0ukevugeaau9p0cwmjlsu",
"amount": "1000alnt",
"raw": "0A91010A8E010A1C2F636F736D6F732E62616E6B2E763162657461312E4D736753656E64126E0A2E6C61636F6E696331347763303777613372377270707275343367396A786B7A68716E686D76666D34646765793673122E6C61636F6E6963317971706337637966657470676D71746B6B30756B657675676561617539703063776D6A6C73751A0C0A04616C6E7412043130303012680A500A460A1F2F636F736D6F732E63727970746F2E736563703235366B312E5075624B657912230A2102F3A1D077638F9FD828C4CF126FE82E0BE98388083F5BC1E1DD4D84132AEBFF8112040A020801185A12140A0E0A04616C6E7412063430303030301080B5181A4088DF7BA4B63EA68E185AB2887C9EC29EBC4158874BC037816B8494AD36D3B2433B5223CECC336D4624BB7FEF4DBB4A8B5F4707ACD8E55443312009E9473DF821"
}
```
Reviewed-on: https://git.vdb.to/cerc-io/laconic-registry-cli/pulls/78
Reviewed-by: David Boreham <dboreham@noreply.git.vdb.to>
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2024-08-20 03:19:48 +00:00
|
|
|
expect(outputObj.tx.code).toEqual(0);
|
|
|
|
expect(outputObj.tx.amount).toEqual(`${sendAmount}${TOKEN_TYPE}`);
|
|
|
|
expect(outputObj.tx.sender).toEqual(testAccount);
|
|
|
|
expect(outputObj.tx.recipient).toEqual(testAccount2);
|
|
|
|
expect(outputObj.accounts.length).toEqual(2);
|
|
|
|
expect(outputObj.accounts).toMatchObject(expectedAccounts);
|
|
|
|
});
|
2024-09-20 09:32:26 +00:00
|
|
|
|
927: Add gettx command and have send command return the tx hash. (#78)
To support https://git.vdb.to/cerc-io/stack-orchestrator/issues/927, add a new token command `gettx` to inspect a previous transaction, and adjust the output of `send` to include the tx details.
For example:
```
❯ laconic registry tokens send --address laconic1yqpc7cyfetpgmqtkk0ukevugeaau9p0cwmjlsu --type alnt --quantity 1000
{
"tx": {
"hash": "977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC",
"height": 343369,
"index": 0,
"code": 0,
"log": "",
"sender": "laconic14wc07wa3r7rppru43g9jxkzhqnhmvfm4dgey6s",
"recipient": "laconic1yqpc7cyfetpgmqtkk0ukevugeaau9p0cwmjlsu",
"amount": "1000alnt"
},
"accounts": [
{
"address": "laconic14wc07wa3r7rppru43g9jxkzhqnhmvfm4dgey6s",
"pubKey": "AvOh0Hdjj5/YKMTPEm/oLgvpg4gIP1vB4d1NhBMq6/+B",
"number": 3,
"sequence": 91,
"balance": [
{
"type": "alnt",
"quantity": 1.2899999999709944e+22
}
]
},
{
"address": "laconic1yqpc7cyfetpgmqtkk0ukevugeaau9p0cwmjlsu",
"pubKey": "A7XYVHLemQYUjXe6VnSDlcyzLnpdJ8CE8zvDiZtgxqnT",
"number": 1,
"sequence": 1,
"balance": [
{
"type": "alnt",
"quantity": 1.289999999991e+22
}
]
}
]
}
```
```
❯ laconic registry tokens gettx --hash 977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC
{
"hash": "977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC",
"height": 343369,
"index": 0,
"code": 0,
"log": "",
"sender": "laconic14wc07wa3r7rppru43g9jxkzhqnhmvfm4dgey6s",
"recipient": "laconic1yqpc7cyfetpgmqtkk0ukevugeaau9p0cwmjlsu",
"amount": "1000alnt",
"raw": "0A91010A8E010A1C2F636F736D6F732E62616E6B2E763162657461312E4D736753656E64126E0A2E6C61636F6E696331347763303777613372377270707275343367396A786B7A68716E686D76666D34646765793673122E6C61636F6E6963317971706337637966657470676D71746B6B30756B657675676561617539703063776D6A6C73751A0C0A04616C6E7412043130303012680A500A460A1F2F636F736D6F732E63727970746F2E736563703235366B312E5075624B657912230A2102F3A1D077638F9FD828C4CF126FE82E0BE98388083F5BC1E1DD4D84132AEBFF8112040A020801185A12140A0E0A04616C6E7412063430303030301080B5181A4088DF7BA4B63EA68E185AB2887C9EC29EBC4158874BC037816B8494AD36D3B2433B5223CECC336D4624BB7FEF4DBB4A8B5F4707ACD8E55443312009E9473DF821"
}
```
Reviewed-on: https://git.vdb.to/cerc-io/laconic-registry-cli/pulls/78
Reviewed-by: David Boreham <dboreham@noreply.git.vdb.to>
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2024-08-20 03:19:48 +00:00
|
|
|
test('laconic registry tokens gettx --hash <hash>', async () => {
|
|
|
|
const sendAmount = 1000000000;
|
|
|
|
|
|
|
|
const sendResult = spawnSync('laconic', ['registry', 'tokens', 'send', '--address', testAccount2, '--type', TOKEN_TYPE, '--quantity', sendAmount.toString()]);
|
|
|
|
const sendOutput = checkResultAndRetrieveOutput(sendResult);
|
|
|
|
expect(sendOutput.tx.code).toEqual(0);
|
|
|
|
|
|
|
|
const gettxResult = spawnSync('laconic', ['registry', 'tokens', 'gettx', '--hash', sendOutput.tx.hash]);
|
|
|
|
const gettxOutput = checkResultAndRetrieveOutput(gettxResult);
|
|
|
|
|
|
|
|
expect(gettxOutput.hash).toEqual(sendOutput.tx.hash);
|
|
|
|
expect(gettxOutput.code).toEqual(0);
|
|
|
|
expect(gettxOutput.amount).toEqual(`${sendAmount}${TOKEN_TYPE}`);
|
|
|
|
expect(gettxOutput.sender).toEqual(testAccount);
|
|
|
|
expect(gettxOutput.recipient).toEqual(testAccount2);
|
2024-01-29 04:46:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Record operations', () => {
|
|
|
|
const gas = 250000;
|
2024-07-30 13:24:46 +00:00
|
|
|
const fees = `250000${TOKEN_TYPE}`;
|
2024-01-29 04:46:32 +00:00
|
|
|
const bondBalance = 1000000000;
|
|
|
|
|
2024-07-30 13:24:46 +00:00
|
|
|
test('laconic registry record publish --filename <record_file> --bond-id <bond_id> --gas <gas> --fees <fees>', async () => {
|
2024-01-29 04:46:32 +00:00
|
|
|
// Create a new bond to be associated with the record
|
|
|
|
({ bondId: testRecordBondId } = createBond(bondBalance));
|
2024-07-30 13:24:46 +00:00
|
|
|
const result = spawnSync('laconic', ['registry', 'record', 'publish', '--filename', testRecordFilePath, '--bond-id', testRecordBondId, '--gas', gas.toString(), '--fees', fees]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expect output object to resultant bond id
|
|
|
|
expect(outputObj.id).toBeDefined();
|
|
|
|
|
|
|
|
testRecordId = outputObj.id;
|
|
|
|
});
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry record list', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'record', 'list']);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected record
|
|
|
|
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: null });
|
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toMatchObject(expectedRecord);
|
|
|
|
expect(outputObj[0].createTime).toBeDefined();
|
|
|
|
expect(outputObj[0].expiryTime).toBeDefined();
|
|
|
|
expect(outputObj[0].owners).toBeDefined();
|
|
|
|
expect(outputObj[0].owners.length).toEqual(1);
|
|
|
|
});
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry record get --id <record_id>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'record', 'get', '--id', testRecordId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected record
|
|
|
|
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: null });
|
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toMatchObject(expectedRecord);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Bond records operations', () => {
|
|
|
|
let testRecordBondId2: string;
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry bond dissociate --id <record_id>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'bond', 'dissociate', '--id', testRecordId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
const recordResult = spawnSync('laconic', ['registry', 'record', 'get', '--id', testRecordId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry bond associate --id <record_id> --bond-id <bond_id>', async () => {
|
2024-01-29 04:46:32 +00:00
|
|
|
// Create a new bond to be associated with the record
|
|
|
|
({ bondId: testRecordBondId2 } = createBond(bondBalance));
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
const result = spawnSync('laconic', ['registry', 'bond', 'associate', '--id', testRecordId, '--bond-id', testRecordBondId2]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
const recordResult = spawnSync('laconic', ['registry', 'record', 'get', '--id', testRecordId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
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-03-19 04:42:42 +00:00
|
|
|
test('laconic registry bond records reassociate --old-bond-id <old_bond_id> --new-bond-id <new_bond_id>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'bond', 'records', 'reassociate', '--old-bond-id', testRecordBondId2, '--new-bond-id', testRecordBondId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
const recordResult = spawnSync('laconic', ['registry', 'record', 'get', '--id', testRecordId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Name authority operations (pre auction)', () => {
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry authority reserve <authority_name>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'authority', 'reserve', testAuthorityName]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expect result
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
});
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry authority whois <authority_name>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'authority', 'whois', testAuthorityName]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
// Expected authority (still in auction)
|
|
|
|
const expectedAuthority = getAuthorityObj({ owner: '', status: 'auction', auction: getAuctionObj({ owner: testAccount }) });
|
|
|
|
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toMatchObject(expectedAuthority);
|
|
|
|
expect(outputObj[0].expiryTime).toBeDefined();
|
|
|
|
expect(outputObj[0].height).toBeGreaterThan(0);
|
|
|
|
|
|
|
|
testAuctionId = outputObj[0].auction.id;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-09-20 05:29:01 +00:00
|
|
|
describe('Authority auction operations', () => {
|
2024-01-29 04:46:32 +00:00
|
|
|
const bidAmount = 25000000;
|
|
|
|
let bidRevealFilePath: string;
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry auction get <auction_id>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
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-03-19 04:42:42 +00:00
|
|
|
test('laconic registry auction bid commit <auction_id> <quantity> <type>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'commit', testAuctionId, bidAmount.toString(), TOKEN_TYPE]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj.reveal_file).toBeDefined();
|
|
|
|
|
|
|
|
bidRevealFilePath = outputObj.reveal_file;
|
|
|
|
});
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry auction bid reveal <auction_id> <file_path>', async () => {
|
2024-01-29 04:46:32 +00:00
|
|
|
// Wait for auction commits duration (60s)
|
|
|
|
await delay(AUCTION_COMMIT_DURATION * 1000);
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
|
|
|
|
|
|
const expectedAuction = getAuctionObj({ owner: testAccount, status: 'reveal' });
|
|
|
|
const expectedBid = getBidObj({ bidder: testAccount });
|
|
|
|
|
|
|
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuction);
|
|
|
|
expect(auctionOutputObj[0].bids[0]).toMatchObject(expectedBid);
|
|
|
|
|
|
|
|
// Reveal bid
|
2024-03-19 04:42:42 +00:00
|
|
|
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'reveal', testAuctionId, bidRevealFilePath]);
|
2024-01-29 04:46:32 +00:00
|
|
|
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,
|
2024-07-30 13:24:46 +00:00
|
|
|
bidAmount: `${bidAmount}alnt`
|
2024-01-29 04:46:32 +00:00
|
|
|
});
|
|
|
|
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Name authority operations (post auction)', () => {
|
|
|
|
const testSubAuthorityName = 'echo.laconic';
|
|
|
|
const testSubAuthorityName2 = 'kube.laconic';
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry authority whois <authority_name>', async () => {
|
2024-01-29 04:46:32 +00:00
|
|
|
// Wait for auction reveals duration (60s)
|
|
|
|
await delay(AUCTION_REVEAL_DURATION * 1000);
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
const result = spawnSync('laconic', ['registry', 'authority', 'whois', testAuthorityName]);
|
2024-01-29 04:46:32 +00:00
|
|
|
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);
|
|
|
|
}, (AUCTION_REVEAL_DURATION + 5) * 1000);
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry authority bond set laconic <bond_id>', async () => {
|
2024-01-29 04:46:32 +00:00
|
|
|
// Create a new bond to be set on the authority
|
|
|
|
const bondBalance = 1000000000;
|
|
|
|
const { bondId } = createBond(bondBalance);
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
const result = spawnSync('laconic', ['registry', 'authority', 'bond', 'set', testAuthorityName, bondId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
// Check updated authority
|
2024-03-19 04:42:42 +00:00
|
|
|
const authorityResult = spawnSync('laconic', ['registry', 'authority', 'whois', testAuthorityName]);
|
2024-01-29 04:46:32 +00:00
|
|
|
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-03-19 04:42:42 +00:00
|
|
|
test('laconic registry authority reserve <sub_authority> (same owner)', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'authority', 'reserve', testSubAuthorityName]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
// Check updated authority
|
2024-03-19 04:42:42 +00:00
|
|
|
const authorityResult = spawnSync('laconic', ['registry', 'authority', 'whois', testSubAuthorityName]);
|
2024-01-29 04:46:32 +00:00
|
|
|
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-03-19 04:42:42 +00:00
|
|
|
test('laconic registry authority reserve <sub_authority> --owner <owner_address> (different owner)', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'authority', 'reserve', testSubAuthorityName2, '--owner', testAccount2]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
// Check updated authority
|
2024-03-19 04:42:42 +00:00
|
|
|
const authorityResult = spawnSync('laconic', ['registry', 'authority', 'whois', testSubAuthorityName2]);
|
2024-01-29 04:46:32 +00:00
|
|
|
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-08-05 10:22:07 +00:00
|
|
|
|
|
|
|
test('laconic registry authority list', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'authority', 'list']);
|
|
|
|
const authoritiesOutputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected authorities
|
|
|
|
const expectedAuthorities = [
|
|
|
|
{ name: 'echo.laconic', entry: { ownerAddress: testAccount, status: 'active' } },
|
|
|
|
{ name: 'kube.laconic', entry: { ownerAddress: testAccount2, status: 'active' } },
|
|
|
|
{ name: 'laconic', entry: { ownerAddress: testAccount, status: 'active' } }
|
|
|
|
];
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(authoritiesOutputObj.length).toEqual(3);
|
|
|
|
expect(authoritiesOutputObj).toMatchObject(expectedAuthorities);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic registry authority list --owner <owner_address>', async () => {
|
|
|
|
let result = spawnSync('laconic', ['registry', 'authority', 'list', '--owner', testAccount]);
|
|
|
|
const authoritiesByOwner1 = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
const expectedAuthoritiesByOwner1 = [
|
|
|
|
{ name: 'echo.laconic', entry: { ownerAddress: testAccount, status: 'active' } },
|
|
|
|
{ name: 'laconic', entry: { ownerAddress: testAccount, status: 'active' } }
|
|
|
|
];
|
|
|
|
|
|
|
|
expect(authoritiesByOwner1.length).toEqual(2);
|
|
|
|
expect(authoritiesByOwner1).toMatchObject(expectedAuthoritiesByOwner1);
|
|
|
|
|
|
|
|
result = spawnSync('laconic', ['registry', 'authority', 'list', '--owner', testAccount2]);
|
|
|
|
const authoritiesByOwner2 = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
const expectedAuthoritiesByOwner2 = [
|
|
|
|
{ name: 'kube.laconic', entry: { ownerAddress: testAccount2, status: 'active' } }
|
|
|
|
];
|
|
|
|
|
|
|
|
expect(authoritiesByOwner2.length).toEqual(1);
|
|
|
|
expect(authoritiesByOwner2).toMatchObject(expectedAuthoritiesByOwner2);
|
|
|
|
});
|
2024-01-29 04:46:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Name operations', () => {
|
2024-03-18 13:58:52 +00:00
|
|
|
const testName = 'lrn://laconic/watcher/erc20';
|
2024-01-29 04:46:32 +00:00
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry name set <name> <record_id>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'name', 'set', testName, testRecordId]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
});
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry name lookup <name>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'name', 'lookup', testName]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj.length).toEqual(1);
|
|
|
|
expect(outputObj[0]).toMatchObject({ latest: { id: testRecordId } });
|
|
|
|
});
|
|
|
|
|
2024-03-19 04:42:42 +00:00
|
|
|
test('laconic registry name resolve <name>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'name', 'resolve', testName]);
|
2024-01-29 04:46:32 +00:00
|
|
|
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-03-19 04:42:42 +00:00
|
|
|
test('laconic registry name delete <name>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'name', 'delete', testName]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj).toEqual({ success: true });
|
|
|
|
|
|
|
|
// Check that name doesn't resolve
|
2024-03-19 04:42:42 +00:00
|
|
|
const resolveResult = spawnSync('laconic', ['registry', 'name', 'resolve', testName]);
|
2024-01-29 04:46:32 +00:00
|
|
|
const resolveOutputObj = checkResultAndRetrieveOutput(resolveResult);
|
|
|
|
expect(resolveOutputObj.length).toEqual(0);
|
|
|
|
});
|
|
|
|
});
|
2024-09-06 09:44:47 +00:00
|
|
|
|
2024-09-20 05:29:01 +00:00
|
|
|
describe('Vickrey Auction operations', () => {
|
|
|
|
const commitFee = 1000;
|
|
|
|
const revealFee = 1000;
|
|
|
|
const minimumBid = 100000;
|
|
|
|
|
|
|
|
const bidAmount = 25000000;
|
|
|
|
let bidRevealFilePath: string;
|
|
|
|
|
2024-09-20 13:20:09 +00:00
|
|
|
test('laconic registry auction create --kind <kind> --commits-duration <commits_duration> --reveals-duration <reveals_duration> --denom <denom> --commit-fee <commit_fee> --reveal-fee <reveal_fee> --minimum-bid <minimum_bid>', async () => {
|
2024-09-20 05:29:01 +00:00
|
|
|
const createAuctionResult = spawnSync('laconic', [
|
|
|
|
'registry',
|
|
|
|
'auction',
|
|
|
|
'create',
|
|
|
|
'--kind', AUCTION_KIND_VICKREY,
|
|
|
|
'--commits-duration', AUCTION_COMMIT_DURATION.toString(),
|
|
|
|
'--reveals-duration', AUCTION_REVEAL_DURATION.toString(),
|
|
|
|
'--denom', TOKEN_TYPE,
|
|
|
|
'--commit-fee', commitFee.toString(),
|
|
|
|
'--reveal-fee', revealFee.toString(),
|
|
|
|
'--minimum-bid', minimumBid.toString()
|
|
|
|
]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(createAuctionResult);
|
|
|
|
|
|
|
|
expect(outputObj).toHaveProperty('auctionId');
|
|
|
|
|
|
|
|
testAuctionId = outputObj.auctionId;
|
|
|
|
const getAuctionResult = spawnSync('laconic', ['registry', 'auction', 'get', '--id', testAuctionId]);
|
|
|
|
const auctionOutputObj = checkResultAndRetrieveOutput(getAuctionResult);
|
|
|
|
|
|
|
|
const expectedAuctionObjPartial = {
|
|
|
|
kind: AUCTION_KIND_VICKREY,
|
|
|
|
status: AUCTION_STATUS.COMMIT,
|
|
|
|
ownerAddress: testAccount,
|
|
|
|
commitFee: { quantity: commitFee },
|
|
|
|
revealFee: { quantity: revealFee },
|
|
|
|
minimumBid: { quantity: minimumBid },
|
|
|
|
winnerAddresses: [],
|
|
|
|
winnerBids: [],
|
|
|
|
maxPrice: { quantity: 0 },
|
|
|
|
numProviders: 0,
|
|
|
|
bids: []
|
|
|
|
};
|
|
|
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic registry auction bid commit <auction_id> <quantity> <type>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'commit', testAuctionId, bidAmount.toString(), TOKEN_TYPE]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj.reveal_file).toBeDefined();
|
|
|
|
|
|
|
|
bidRevealFilePath = outputObj.reveal_file;
|
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic registry auction bid reveal <auction_id> <file_path>', async () => {
|
|
|
|
// Wait for auction commits duration (60s)
|
|
|
|
await delay(AUCTION_COMMIT_DURATION * 1000);
|
|
|
|
|
|
|
|
let auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
|
|
|
let auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
|
|
|
|
|
|
const expectedAuctionObjPartial = {
|
|
|
|
status: AUCTION_STATUS.REVEAL,
|
|
|
|
ownerAddress: testAccount,
|
|
|
|
winnerAddresses: [],
|
|
|
|
winnerBids: [],
|
|
|
|
bids: [{
|
|
|
|
bidderAddress: testAccount,
|
|
|
|
status: AUCTION_STATUS.COMMIT,
|
|
|
|
bidAmount: { quantity: 0 }
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
|
|
|
|
|
|
|
// Reveal bid
|
|
|
|
const result = spawnSync('laconic', ['registry', '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}${TOKEN_TYPE}`
|
|
|
|
});
|
|
|
|
|
2024-09-20 09:32:26 +00:00
|
|
|
// Get auction with revealed bid
|
|
|
|
auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
|
|
|
auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
|
|
|
|
|
|
const expectedAuctionObjPartialOnBidReveal = {
|
|
|
|
status: AUCTION_STATUS.REVEAL,
|
|
|
|
winnerAddresses: [],
|
|
|
|
bids: [{
|
|
|
|
bidderAddress: testAccount,
|
|
|
|
status: AUCTION_STATUS.REVEAL,
|
|
|
|
bidAmount: { quantity: bidAmount }
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartialOnBidReveal);
|
|
|
|
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
|
|
|
|
|
|
|
|
test('laconic registry auction get <auction_id>', async () => {
|
|
|
|
// Wait for auction reveals duration (60s)
|
|
|
|
await delay(AUCTION_REVEAL_DURATION * 1000);
|
|
|
|
|
|
|
|
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
|
|
|
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
|
|
|
|
|
|
const expectedAuctionObjPartial = {
|
|
|
|
status: AUCTION_STATUS.COMPLETED,
|
|
|
|
ownerAddress: testAccount,
|
|
|
|
winnerAddresses: [testAccount],
|
|
|
|
winnerBids: [{ quantity: bidAmount }],
|
|
|
|
winnerPrice: { quantity: bidAmount }
|
|
|
|
};
|
|
|
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
|
|
|
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Provider Auction operations', () => {
|
|
|
|
const commitFee = 1000;
|
|
|
|
const revealFee = 1000;
|
|
|
|
const maxPrice = 1000000;
|
|
|
|
const numProviders = 5;
|
|
|
|
const bidAmount = 25000;
|
|
|
|
let bidRevealFilePath: string;
|
|
|
|
|
2024-09-20 13:20:09 +00:00
|
|
|
test('laconic registry auction create --kind <kind> --commits-duration <commits_duration> --reveals-duration <reveals_duration> --denom <denom> --commit-fee <commit_fee> --reveal-fee <reveal_fee> --max-price <max_price> --num-providers <num_providers>', async () => {
|
2024-09-20 09:32:26 +00:00
|
|
|
const createAuctionResult = spawnSync('laconic', [
|
|
|
|
'registry',
|
|
|
|
'auction',
|
|
|
|
'create',
|
|
|
|
'--kind', AUCTION_KIND_PROVIDER,
|
|
|
|
'--commits-duration', AUCTION_COMMIT_DURATION.toString(),
|
|
|
|
'--reveals-duration', AUCTION_REVEAL_DURATION.toString(),
|
|
|
|
'--denom', TOKEN_TYPE,
|
|
|
|
'--commit-fee', commitFee.toString(),
|
|
|
|
'--reveal-fee', revealFee.toString(),
|
|
|
|
'--max-price', maxPrice.toString(),
|
|
|
|
'--num-providers', numProviders.toString()
|
|
|
|
]);
|
|
|
|
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(createAuctionResult);
|
|
|
|
|
|
|
|
expect(outputObj).toHaveProperty('auctionId');
|
|
|
|
|
|
|
|
testAuctionId = outputObj.auctionId;
|
|
|
|
const getAuctionResult = spawnSync('laconic', ['registry', 'auction', 'get', '--id', testAuctionId]);
|
|
|
|
const auctionOutputObj = checkResultAndRetrieveOutput(getAuctionResult);
|
|
|
|
|
|
|
|
const expectedAuctionObjPartial = {
|
|
|
|
kind: AUCTION_KIND_PROVIDER,
|
|
|
|
status: AUCTION_STATUS.COMMIT,
|
|
|
|
ownerAddress: testAccount,
|
|
|
|
commitFee: { quantity: commitFee },
|
|
|
|
revealFee: { quantity: revealFee },
|
|
|
|
minimumBid: { quantity: 0 },
|
|
|
|
winnerAddresses: [],
|
|
|
|
winnerBids: [],
|
|
|
|
maxPrice: { quantity: maxPrice },
|
|
|
|
numProviders: numProviders,
|
|
|
|
bids: []
|
|
|
|
};
|
|
|
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic registry auction bid commit <auction_id> <quantity> <type>', async () => {
|
|
|
|
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'commit', testAuctionId, bidAmount.toString(), TOKEN_TYPE]);
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
|
|
|
|
// Expected output
|
|
|
|
expect(outputObj.reveal_file).toBeDefined();
|
|
|
|
|
|
|
|
bidRevealFilePath = outputObj.reveal_file;
|
|
|
|
});
|
|
|
|
|
|
|
|
test('laconic registry auction bid reveal <auction_id> <file_path>', async () => {
|
|
|
|
// Wait for auction commits duration (60s)
|
|
|
|
await delay(AUCTION_COMMIT_DURATION * 1000);
|
|
|
|
|
|
|
|
let auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
|
|
|
let auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
|
|
|
|
|
|
const expectedAuctionObjPartial = {
|
|
|
|
status: AUCTION_STATUS.REVEAL,
|
|
|
|
ownerAddress: testAccount,
|
|
|
|
winnerAddresses: [],
|
|
|
|
winnerBids: [],
|
|
|
|
bids: [{
|
|
|
|
bidderAddress: testAccount,
|
|
|
|
status: AUCTION_STATUS.COMMIT,
|
|
|
|
bidAmount: { quantity: 0 }
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
|
|
|
|
|
|
|
// Reveal bid
|
|
|
|
const result = spawnSync('laconic', ['registry', '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}${TOKEN_TYPE}`
|
|
|
|
});
|
|
|
|
|
|
|
|
// Get auction with revealed bid
|
2024-09-20 05:29:01 +00:00
|
|
|
auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
|
|
|
auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
|
|
|
|
|
|
const expectedAuctionObjPartialOnBidReveal = {
|
|
|
|
status: AUCTION_STATUS.REVEAL,
|
|
|
|
winnerAddresses: [],
|
|
|
|
bids: [{
|
|
|
|
bidderAddress: testAccount,
|
|
|
|
status: AUCTION_STATUS.REVEAL,
|
|
|
|
bidAmount: { quantity: bidAmount }
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartialOnBidReveal);
|
|
|
|
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
|
|
|
|
|
|
|
|
test('laconic registry auction get <auction_id>', async () => {
|
|
|
|
// Wait for auction reveals duration (60s)
|
|
|
|
await delay(AUCTION_REVEAL_DURATION * 1000);
|
|
|
|
|
|
|
|
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
|
|
|
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
|
|
|
|
|
|
|
const expectedAuctionObjPartial = {
|
|
|
|
status: AUCTION_STATUS.COMPLETED,
|
|
|
|
ownerAddress: testAccount,
|
|
|
|
winnerAddresses: [testAccount],
|
|
|
|
winnerBids: [{ quantity: bidAmount }],
|
|
|
|
winnerPrice: { quantity: bidAmount }
|
|
|
|
};
|
|
|
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
|
|
|
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
|
|
|
|
});
|
|
|
|
|
2024-09-06 09:44:47 +00:00
|
|
|
describe('Gas and fees config', () => {
|
|
|
|
const bondAmount = 1000;
|
|
|
|
|
|
|
|
test('gas set, fees set to Xalnt', async () => {
|
|
|
|
// gasPrice not set
|
|
|
|
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
|
|
|
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
expect(outputObj.bondId).toBeDefined();
|
|
|
|
|
|
|
|
// gasPrice set (lower than min gas price)
|
|
|
|
updateGasAndFeesConfig(undefined, undefined, '0.00001alnt');
|
|
|
|
const result1 = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
|
|
|
|
|
|
|
const outputObj1 = checkResultAndRetrieveOutput(result1);
|
|
|
|
expect(outputObj1.bondId).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('gas not set, fees not set, gasPrice set', async () => {
|
|
|
|
updateGasAndFeesConfig(null, null, '1alnt');
|
|
|
|
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
|
|
|
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
expect(outputObj.bondId).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('gas not set, fees set without token suffix, gasPrice set', async () => {
|
|
|
|
updateGasAndFeesConfig(null, '1.8', '1alnt');
|
|
|
|
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
|
|
|
|
|
|
|
const outputObj = checkResultAndRetrieveOutput(result);
|
|
|
|
expect(outputObj.bondId).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('gas not set, fees not set, gasPrice not set', async () => {
|
|
|
|
updateGasAndFeesConfig(null, null, null);
|
|
|
|
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
|
|
|
|
|
|
|
expect(result.status).toBe(1);
|
|
|
|
|
|
|
|
const output = result.stdout.toString().trim();
|
|
|
|
const errorOutput = result.stderr.toString().trim();
|
|
|
|
|
|
|
|
expect(output).toBe('');
|
|
|
|
expect(errorOutput).toContain('Gas price must be set in the client options when auto gas is used.');
|
|
|
|
});
|
|
|
|
});
|
2024-01-29 04:46:32 +00:00
|
|
|
});
|
|
|
|
});
|