diff --git a/src/cmds/registry-cmds/auction-cmds/create.ts b/src/cmds/registry-cmds/auction-cmds/create.ts index 3f03b67..d16b189 100644 --- a/src/cmds/registry-cmds/auction-cmds/create.ts +++ b/src/cmds/registry-cmds/auction-cmds/create.ts @@ -2,9 +2,7 @@ import { Arguments } from 'yargs'; import assert from 'assert'; import Long from 'long'; -import { AUCTION_KIND_PROVIDER, AUCTION_KIND_VICKREY, Registry } from '@cerc-io/registry-sdk'; -import { MsgCreateAuctionResponse } from '@cerc-io/registry-sdk/dist/proto/cerc/auction/v1/tx'; -import { Duration } from '@cerc-io/registry-sdk/dist/proto/google/protobuf/duration'; +import { AUCTION_KIND_PROVIDER, AUCTION_KIND_VICKREY, Duration, Registry } from '@cerc-io/registry-sdk'; import { coin } from '@cosmjs/amino'; import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util'; @@ -98,13 +96,13 @@ export const handler = async (argv: Arguments) => { const fee = getGasAndFees(argv, registryConfig); - let result: MsgCreateAuctionResponse; + let result: any; if (kind === AUCTION_KIND_VICKREY) { result = await registry.createAuction({ commitsDuration, revealsDuration, commitFee, revealFee, minimumBid }, privateKey, fee); } else { result = await registry.createProviderAuction({ commitsDuration, revealsDuration, commitFee, revealFee, maxPrice, numProviders }, privateKey, fee); } - const jsonString = `{"auctionId":"${result.auction?.id}"}`; + const jsonString = `{"auctionId":"${result.auction?.id}"}`; txOutput(result, jsonString, argv.output, argv.verbose); }; diff --git a/test/cli.test.ts b/test/cli.test.ts index 3aba5a4..4786a5b 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import assert from 'assert'; import { spawnSync } from 'child_process'; -import { AUCTION_KIND_VICKREY } from '@cerc-io/registry-sdk'; +import { AUCTION_KIND_PROVIDER, AUCTION_KIND_VICKREY } from '@cerc-io/registry-sdk'; import { CHAIN_ID, @@ -228,6 +228,7 @@ describe('Test laconic CLI commands', () => { expect(outputObj.accounts.length).toEqual(2); expect(outputObj.accounts).toMatchObject(expectedAccounts); }); + test('laconic registry tokens gettx --hash ', async () => { const sendAmount = 1000000000; @@ -680,6 +681,133 @@ describe('Test laconic CLI commands', () => { bidAmount: `${bidAmount}${TOKEN_TYPE}` }); + // 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 ', 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; + + test('laconic registry auction create --kind --commits-duration --reveals-duration --commit-fee --reveal-fee --max-price --num-providers ', async () => { + 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 ', 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 ', 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 auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]); auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);