Update create auction CLI and add auction tests
This commit is contained in:
parent
3cf35dad43
commit
d27f9ae43d
23
README.md
23
README.md
@ -660,26 +660,29 @@ Reassociate records (switch bond):
|
|||||||
laconic registry bond records reassociate --old-bond-id 5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0 --new-bond-id 3e11c61f179897e4b12e9b63de35d36f88ac146755e7a28ce0bcdd07cf3a03ae
|
laconic registry bond records reassociate --old-bond-id 5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0 --new-bond-id 3e11c61f179897e4b12e9b63de35d36f88ac146755e7a28ce0bcdd07cf3a03ae
|
||||||
```
|
```
|
||||||
|
|
||||||
Create `provider` auction:
|
Create a `provider` auction:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry auction create --kind provider --commits-duration 60 --reveals-duration 60 --commit-fee 1000 --reveal-fee 1000 --max-price 100000 --num-providers 2
|
laconic registry auction create --kind provider --commits-duration 60 --reveals-duration 60 --denom alnt --commit-fee 1000 --reveal-fee 1000 --max-price 100000 --num-providers 1
|
||||||
|
|
||||||
{"auctionId":"73c5fa4b91bb973641ccbb6901a8404745fb8793c95485b00d5a791e6b6c1630"}
|
{"auctionId":"73c5fa4b91bb973641ccbb6901a8404745fb8793c95485b00d5a791e6b6c1630"}
|
||||||
|
|
||||||
|
# Set auction id in a variable
|
||||||
|
AUCTION=
|
||||||
```
|
```
|
||||||
|
|
||||||
Commit an auction bid:
|
Commit an auction bid:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry auction bid commit 73c5fa4b91bb973641ccbb6901a8404745fb8793c95485b00d5a791e6b6c1630 25000000 alnt
|
laconic registry auction bid commit $AUCTION 25000 alnt
|
||||||
|
|
||||||
{"reveal_file":"./out/bafyreiai5upey4562ont54pe7m3buiphtd6n3q2vr5lxdcj3gpyklbbgvy.json"}
|
{"reveal_file":"/home/user/laconic-registry-cli/out/bafyreiai5upey4562ont54pe7m3buiphtd6n3q2vr5lxdcj3gpyklbbgvy.json"}
|
||||||
```
|
```
|
||||||
|
|
||||||
Reveal an auction bid:
|
Reveal an auction bid:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry auction bid reveal b66b74048fc360de6a926123b760e6485276d90ad2274b5386c02664cd04bace ./out/bafyreifjkhiakayvvaasnsw7ufaax54ncow4xuycqnox7hxay34c6yod7a.json
|
laconic registry auction bid reveal $AUCTION /home/user/laconic-registry-cli/out/bafyreiai5upey4562ont54pe7m3buiphtd6n3q2vr5lxdcj3gpyklbbgvy.json
|
||||||
|
|
||||||
{"success": true}
|
{"success": true}
|
||||||
```
|
```
|
||||||
@ -687,7 +690,7 @@ laconic registry auction bid reveal b66b74048fc360de6a926123b760e6485276d90ad227
|
|||||||
Check the auction state on completion:
|
Check the auction state on completion:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
laconic registry auction get b66b74048fc360de6a926123b760e6485276d90ad2274b5386c02664cd04bace
|
laconic registry auction get $AUCTION
|
||||||
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@ -716,18 +719,18 @@ laconic registry auction get b66b74048fc360de6a926123b760e6485276d90ad2274b5386c
|
|||||||
"winnerBids": [
|
"winnerBids": [
|
||||||
{
|
{
|
||||||
"type": "alnt",
|
"type": "alnt",
|
||||||
"quantity": 26000
|
"quantity": 25000
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"winnerPrice": {
|
"winnerPrice": {
|
||||||
"type": "alnt",
|
"type": "alnt",
|
||||||
"quantity": 26000
|
"quantity": 25000
|
||||||
},
|
},
|
||||||
"maxPrice": {
|
"maxPrice": {
|
||||||
"type": "alnt",
|
"type": "alnt",
|
||||||
"quantity": 100000
|
"quantity": 100000
|
||||||
},
|
},
|
||||||
"numProviders": 2,
|
"numProviders": 1,
|
||||||
"bids": [
|
"bids": [
|
||||||
{
|
{
|
||||||
"bidderAddress": "laconic13qrlfkgl02wgwpw0n4j8kswygwnukphy92249r",
|
"bidderAddress": "laconic13qrlfkgl02wgwpw0n4j8kswygwnukphy92249r",
|
||||||
@ -745,7 +748,7 @@ laconic registry auction get b66b74048fc360de6a926123b760e6485276d90ad2274b5386c
|
|||||||
},
|
},
|
||||||
"bidAmount": {
|
"bidAmount": {
|
||||||
"type": "alnt",
|
"type": "alnt",
|
||||||
"quantity": 26000
|
"quantity": 25000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -16,19 +16,19 @@ export const desc = 'Create auction.';
|
|||||||
export const builder = {
|
export const builder = {
|
||||||
kind: {
|
kind: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
describe: 'Type of auction (vickrey | provider)'
|
describe: 'Auction kind (vickrey | provider)'
|
||||||
},
|
},
|
||||||
'commits-duration': {
|
'commits-duration': {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
describe: 'Duration for commits phase in seconds'
|
describe: 'Duration for bid commit phase in seconds'
|
||||||
},
|
},
|
||||||
'reveals-duration': {
|
'reveals-duration': {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
describe: 'Duration for reveals phase in seconds'
|
describe: 'Duration for bid reveal phase in seconds'
|
||||||
},
|
},
|
||||||
denom: {
|
denom: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
describe: 'Denom'
|
describe: 'Denom to use'
|
||||||
},
|
},
|
||||||
'commit-fee': {
|
'commit-fee': {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
@ -36,19 +36,21 @@ export const builder = {
|
|||||||
},
|
},
|
||||||
'reveal-fee': {
|
'reveal-fee': {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
describe: 'Fee for revealing bids in the auction'
|
describe: 'Fee for revealing a bid in the auction'
|
||||||
},
|
},
|
||||||
'minimum-bid': {
|
'minimum-bid': {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
default: 0,
|
||||||
describe: 'Minimum bid amount (only for vickrey auction)'
|
describe: 'Minimum bid amount (only for vickrey auction)'
|
||||||
},
|
},
|
||||||
'max-price': {
|
'max-price': {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
describe: 'Maximum price (only for provider auction)'
|
default: 0,
|
||||||
|
describe: 'Max acceptable bid price (only for provider auction)'
|
||||||
},
|
},
|
||||||
'num-providers': {
|
'num-providers': {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
describe: 'Number of providers (only for provider auction)'
|
describe: 'Number ofdesired providers (only for provider auction)'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -56,14 +58,24 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const { config } = argv;
|
const { config } = argv;
|
||||||
|
|
||||||
const kind = argv.kind as string;
|
const kind = argv.kind as string;
|
||||||
const commitsDuration = Duration.fromPartial({
|
if (kind === AUCTION_KIND_VICKREY) {
|
||||||
seconds: Long.fromNumber(argv.commitsDuration as number),
|
assert(argv.minimumBid, 'Invalid minimum bid.');
|
||||||
nanos: 0
|
assert(!argv.maxPrice, `Max price can only be used with ${AUCTION_KIND_PROVIDER} auction.`);
|
||||||
});
|
assert(!argv.numProviders, `Num providers can only be used with ${AUCTION_KIND_PROVIDER} auction.`);
|
||||||
const revealsDuration = Duration.fromPartial({
|
} else if (kind === AUCTION_KIND_PROVIDER) {
|
||||||
seconds: Long.fromNumber(argv.revealsDuration as number),
|
assert(argv.maxPrice, 'Invalid max price.');
|
||||||
nanos: 0
|
assert(argv.numProviders, 'Invalid num providers.');
|
||||||
});
|
assert(!argv.minimumBid, `Minimum bid can only be used with ${AUCTION_KIND_VICKREY} auction.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(argv.commitsDuration, 'Invalid commits duration.');
|
||||||
|
assert(argv.revealsDuration, 'Invalid reveals duration.');
|
||||||
|
assert(argv.commitFee, 'Invalid commit fee.');
|
||||||
|
assert(argv.revealFee, 'Invalid reveal fee.');
|
||||||
|
|
||||||
|
const commitsDuration = Duration.fromPartial({ seconds: Long.fromNumber(argv.commitsDuration as number) });
|
||||||
|
const revealsDuration = Duration.fromPartial({ seconds: Long.fromNumber(argv.revealsDuration as number) });
|
||||||
|
|
||||||
const denom = argv.denom as string;
|
const denom = argv.denom as string;
|
||||||
const commitFee = coin(argv.commitFee as string, denom);
|
const commitFee = coin(argv.commitFee as string, denom);
|
||||||
const revealFee = coin(argv.revealFee as string, denom);
|
const revealFee = coin(argv.revealFee as string, denom);
|
||||||
@ -71,25 +83,8 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const maxPrice = coin(argv.maxPrice as string, denom);
|
const maxPrice = coin(argv.maxPrice as string, denom);
|
||||||
const numProviders = argv.numProviders as number;
|
const numProviders = argv.numProviders as number;
|
||||||
|
|
||||||
const validKinds = [AUCTION_KIND_VICKREY, AUCTION_KIND_PROVIDER];
|
const validAuctionKinds = [AUCTION_KIND_VICKREY, AUCTION_KIND_PROVIDER];
|
||||||
assert(validKinds.includes(kind), 'Invalid auction kind.');
|
assert(validAuctionKinds.includes(kind), `Invalid auction kind, has to be one of ${validAuctionKinds}.`);
|
||||||
|
|
||||||
if (kind === AUCTION_KIND_VICKREY) {
|
|
||||||
assert(commitsDuration, 'Invalid commits duration.');
|
|
||||||
assert(revealsDuration, 'Invalid reveals duration.');
|
|
||||||
assert(commitFee, 'Invalid commit fee.');
|
|
||||||
assert(revealFee, 'Invalid reveal fee.');
|
|
||||||
assert(!argv.maxPrice, 'Max price should not be provided for vickrey auction.');
|
|
||||||
assert(!argv.numProviders, 'Num providers should not be provided for vickrey auction.');
|
|
||||||
} else if (kind === AUCTION_KIND_PROVIDER) {
|
|
||||||
assert(commitsDuration, 'Invalid commits duration.');
|
|
||||||
assert(revealsDuration, 'Invalid reveals duration.');
|
|
||||||
assert(commitFee, 'Invalid commit fee.');
|
|
||||||
assert(revealFee, 'Invalid reveal fee.');
|
|
||||||
assert(maxPrice, 'Invalid max price.');
|
|
||||||
assert(numProviders, 'Invalid number of providers.');
|
|
||||||
assert(!argv.minimumBid, 'Minimum bid should not be provided for provider auction.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const { services: { registry: registryConfig } } = getConfig(config as string);
|
const { services: { registry: registryConfig } } = getConfig(config as string);
|
||||||
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
## Run CLI tests
|
# Run CLI tests
|
||||||
|
|
||||||
* Follow the project `Setup` and `Account Setup` from root [README](./../README.md)
|
* Follow the project `Setup` and `Account Setup` from root [README](./../README.md)
|
||||||
|
|
||||||
|
130
test/cli.test.ts
130
test/cli.test.ts
@ -2,6 +2,8 @@ import fs from 'fs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { spawnSync } from 'child_process';
|
import { spawnSync } from 'child_process';
|
||||||
|
|
||||||
|
import { AUCTION_KIND_VICKREY } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CHAIN_ID,
|
CHAIN_ID,
|
||||||
TOKEN_TYPE,
|
TOKEN_TYPE,
|
||||||
@ -16,7 +18,8 @@ import {
|
|||||||
getAuthorityObj,
|
getAuthorityObj,
|
||||||
getAuctionObj,
|
getAuctionObj,
|
||||||
getBidObj,
|
getBidObj,
|
||||||
updateGasAndFeesConfig
|
updateGasAndFeesConfig,
|
||||||
|
AUCTION_STATUS
|
||||||
} from './helpers';
|
} from './helpers';
|
||||||
|
|
||||||
describe('Test laconic CLI commands', () => {
|
describe('Test laconic CLI commands', () => {
|
||||||
@ -369,7 +372,7 @@ describe('Test laconic CLI commands', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Auction operations', () => {
|
describe('Authority auction operations', () => {
|
||||||
const bidAmount = 25000000;
|
const bidAmount = 25000000;
|
||||||
let bidRevealFilePath: string;
|
let bidRevealFilePath: string;
|
||||||
|
|
||||||
@ -587,6 +590,129 @@ describe('Test laconic CLI commands', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Vickrey Auction operations', () => {
|
||||||
|
const commitFee = 1000;
|
||||||
|
const revealFee = 1000;
|
||||||
|
const minimumBid = 100000;
|
||||||
|
|
||||||
|
const bidAmount = 25000000;
|
||||||
|
let bidRevealFilePath: string;
|
||||||
|
|
||||||
|
test('laconic registry auction create --kind <kind> --commits-duration <commits_duration> --reveals-duration <reveals_duration> --commit-fee <commit_fee> --reveal-fee <reveal_fee> --minimum-bid <minimum_bid>', async () => {
|
||||||
|
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}`
|
||||||
|
});
|
||||||
|
|
||||||
|
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('Gas and fees config', () => {
|
describe('Gas and fees config', () => {
|
||||||
const bondAmount = 1000;
|
const bondAmount = 1000;
|
||||||
|
|
||||||
|
@ -8,6 +8,12 @@ import { getConfig } from '../src/util';
|
|||||||
export const CHAIN_ID = 'laconic_9000-1';
|
export const CHAIN_ID = 'laconic_9000-1';
|
||||||
export const TOKEN_TYPE = 'alnt';
|
export const TOKEN_TYPE = 'alnt';
|
||||||
|
|
||||||
|
export enum AUCTION_STATUS {
|
||||||
|
COMMIT = 'commit',
|
||||||
|
REVEAL = 'reveal',
|
||||||
|
COMPLETED = 'completed'
|
||||||
|
}
|
||||||
|
|
||||||
export const AUCTION_FEES = {
|
export const AUCTION_FEES = {
|
||||||
commit: 1000000,
|
commit: 1000000,
|
||||||
reveal: 1000000,
|
reveal: 1000000,
|
||||||
@ -17,6 +23,10 @@ export const AUCTION_COMMIT_DURATION = 60; // 60s
|
|||||||
export const AUCTION_REVEAL_DURATION = 60; // 60s
|
export const AUCTION_REVEAL_DURATION = 60; // 60s
|
||||||
|
|
||||||
export function checkResultAndRetrieveOutput (result: SpawnSyncReturns<Buffer>): any {
|
export function checkResultAndRetrieveOutput (result: SpawnSyncReturns<Buffer>): any {
|
||||||
|
if (result.status !== 0) {
|
||||||
|
console.log('stderr', result.stderr.toString().trim());
|
||||||
|
}
|
||||||
|
|
||||||
expect(result.status).toBe(0);
|
expect(result.status).toBe(0);
|
||||||
|
|
||||||
const errorOutput = result.stderr.toString().trim();
|
const errorOutput = result.stderr.toString().trim();
|
||||||
|
Loading…
Reference in New Issue
Block a user