Update types used for create auction methods
This commit is contained in:
parent
233063881c
commit
daa4297e72
@ -1,22 +1,13 @@
|
||||
import Long from 'long';
|
||||
|
||||
import { coin } from '@cosmjs/amino';
|
||||
import { Coin } from '@cosmjs/proto-signing';
|
||||
|
||||
import { Registry, Account, createBid, INVALID_BID_ERROR } from './index';
|
||||
import { getConfig } from './testing/helper';
|
||||
import { DENOM } from './constants';
|
||||
import { Duration } from './proto/google/protobuf/duration';
|
||||
|
||||
jest.setTimeout(30 * 60 * 1000);
|
||||
const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
||||
|
||||
const duration = 60;
|
||||
const commitsDuration = Duration.fromPartial({ seconds: Long.fromNumber(60) });
|
||||
const revealsDuration = Duration.fromPartial({ seconds: Long.fromNumber(60) });
|
||||
|
||||
const commitFee = coin('1000', DENOM);
|
||||
const revealFee = coin('1000', DENOM);
|
||||
const commitFee = '1000';
|
||||
const revealFee = '1000';
|
||||
|
||||
const creatorInitialBalance = 1000000000000;
|
||||
const bidderInitialBalance = 20000000;
|
||||
@ -31,7 +22,7 @@ const auctionTests = () => {
|
||||
let bidderAccounts: { address: string, privateKey: string, bid?: any }[] = [];
|
||||
|
||||
const numBidders = 3;
|
||||
let bidAmounts: Coin[] = [];
|
||||
let bidAmounts: string[] = [];
|
||||
|
||||
beforeAll(async () => {
|
||||
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||
@ -56,12 +47,13 @@ const auctionTests = () => {
|
||||
});
|
||||
|
||||
test('Create a vickrey auction', async () => {
|
||||
const minimumBid = coin('1000000', DENOM);
|
||||
const minimumBid = '1000000';
|
||||
|
||||
const auction = await registry.createAuction(
|
||||
{
|
||||
commitsDuration,
|
||||
revealsDuration,
|
||||
commitsDuration: duration.toString(),
|
||||
revealsDuration: duration.toString(),
|
||||
denom: DENOM,
|
||||
commitFee,
|
||||
revealFee,
|
||||
minimumBid
|
||||
@ -77,8 +69,8 @@ const auctionTests = () => {
|
||||
|
||||
test('Commit bids.', async () => {
|
||||
for (let i = 0; i < numBidders; i++) {
|
||||
bidAmounts.push(coin((lowestBidAmount + (i * 500)).toString(), DENOM));
|
||||
bidderAccounts[i].bid = await createBid(chainId, auctionId, bidderAccounts[i].address, `${bidAmounts[i].amount}${bidAmounts[i].denom}`);
|
||||
bidAmounts.push((lowestBidAmount + (i * 500)).toString());
|
||||
bidderAccounts[i].bid = await createBid(chainId, auctionId, bidderAccounts[i].address, `${bidAmounts[i]}${DENOM}`);
|
||||
await registry.commitBid({ auctionId, commitHash: bidderAccounts[i].bid.commitHash }, bidderAccounts[i].privateKey, fee);
|
||||
}
|
||||
|
||||
@ -113,7 +105,7 @@ const auctionTests = () => {
|
||||
expect(bid.status).toEqual('reveal');
|
||||
});
|
||||
|
||||
const expectedBidAmounts = bidAmounts.map(bidAmount => { return { quantity: bidAmount.amount, type: bidAmount.denom }; });
|
||||
const expectedBidAmounts = bidAmounts.map(bidAmount => { return { quantity: bidAmount.toString(), type: DENOM }; });
|
||||
const actualBidAmounts = auction.bids.map((bid: any) => bid.bidAmount);
|
||||
expect(actualBidAmounts).toEqual(expect.arrayContaining(expectedBidAmounts));
|
||||
|
||||
@ -124,7 +116,7 @@ const auctionTests = () => {
|
||||
|
||||
const [{ type, quantity }] = bidderrAccountObj.balance;
|
||||
const actualBalance = parseInt(quantity);
|
||||
const expectedBalance = bidderInitialBalance - parseInt(bidAmounts[i].amount);
|
||||
const expectedBalance = bidderInitialBalance - parseInt(bidAmounts[i]);
|
||||
|
||||
expect(type).toBe(DENOM);
|
||||
expect(actualBalance).toBeLessThan(expectedBalance);
|
||||
@ -163,7 +155,7 @@ const auctionTests = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const providerAuctionTestsWithBids = (bidsAmount: number[], numProviders: number) => {
|
||||
const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number) => {
|
||||
let registry: Registry;
|
||||
let auctionId: string;
|
||||
|
||||
@ -172,10 +164,8 @@ const providerAuctionTestsWithBids = (bidsAmount: number[], numProviders: number
|
||||
let sortedBidders: { address: string, privateKey: string, bid?: any }[] = [];
|
||||
let invalidBidderAddresses: string[] = [];
|
||||
|
||||
const bidAmounts: Coin[] = bidsAmount.map(amount => coin(amount.toString(), DENOM));
|
||||
const numBidders = bidAmounts.length;
|
||||
|
||||
const maxPrice = coin((10 * lowestBidAmount).toString(), DENOM);
|
||||
const maxPrice = 10 * lowestBidAmount;
|
||||
|
||||
beforeAll(async () => {
|
||||
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||
@ -202,11 +192,12 @@ const providerAuctionTestsWithBids = (bidsAmount: number[], numProviders: number
|
||||
test('Create a provider auction', async () => {
|
||||
const auction = await registry.createProviderAuction(
|
||||
{
|
||||
commitsDuration,
|
||||
revealsDuration,
|
||||
commitsDuration: duration.toString(),
|
||||
revealsDuration: duration.toString(),
|
||||
denom: DENOM,
|
||||
commitFee,
|
||||
revealFee,
|
||||
maxPrice,
|
||||
maxPrice: maxPrice.toString(),
|
||||
numProviders
|
||||
},
|
||||
auctionCreatorAccount.privateKey, fee
|
||||
@ -222,7 +213,7 @@ const providerAuctionTestsWithBids = (bidsAmount: number[], numProviders: number
|
||||
|
||||
const [{ type, quantity }] = creatorAccountObj.balance;
|
||||
const actualBalance = parseInt(quantity);
|
||||
const expectedBalance = creatorInitialBalance - (parseInt(maxPrice.amount) * numProviders) - 200000;
|
||||
const expectedBalance = creatorInitialBalance - (maxPrice * numProviders) - 200000;
|
||||
|
||||
expect(type).toBe(DENOM);
|
||||
expect(actualBalance).toBe(expectedBalance);
|
||||
@ -230,7 +221,7 @@ const providerAuctionTestsWithBids = (bidsAmount: number[], numProviders: number
|
||||
|
||||
test('Commit bids.', async () => {
|
||||
for (let i = 0; i < numBidders; i++) {
|
||||
bidderAccounts[i].bid = await createBid(chainId, auctionId, bidderAccounts[i].address, `${bidAmounts[i].amount}${bidAmounts[i].denom}`);
|
||||
bidderAccounts[i].bid = await createBid(chainId, auctionId, bidderAccounts[i].address, `${bidAmounts[i]}${DENOM}`);
|
||||
await registry.commitBid({ auctionId, commitHash: bidderAccounts[i].bid.commitHash }, bidderAccounts[i].privateKey, fee);
|
||||
}
|
||||
|
||||
@ -239,7 +230,7 @@ const providerAuctionTestsWithBids = (bidsAmount: number[], numProviders: number
|
||||
});
|
||||
|
||||
for (const bidder of sortedBidders) {
|
||||
if (parseInt(bidder.bid.reveal.bidAmount) > parseInt(maxPrice.amount)) {
|
||||
if (parseInt(bidder.bid.reveal.bidAmount) > maxPrice) {
|
||||
invalidBidderAddresses.push(bidder.address);
|
||||
}
|
||||
}
|
||||
@ -284,7 +275,7 @@ const providerAuctionTestsWithBids = (bidsAmount: number[], numProviders: number
|
||||
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
||||
expect(auction.status).toEqual('reveal');
|
||||
|
||||
const validBids = sortedBidders.map((bidder: any) => {
|
||||
const expectedBids = sortedBidders.map((bidder: any) => {
|
||||
if (invalidBidderAddresses.includes(bidder.address)) {
|
||||
return '0';
|
||||
}
|
||||
@ -292,7 +283,7 @@ const providerAuctionTestsWithBids = (bidsAmount: number[], numProviders: number
|
||||
});
|
||||
|
||||
const actualBidAmounts = auction.bids.map((bid: any) => `${bid.bidAmount.quantity}${bid.bidAmount.type}`);
|
||||
expect(actualBidAmounts).toEqual(expect.arrayContaining(validBids));
|
||||
expect(actualBidAmounts).toEqual(expect.arrayContaining(expectedBids));
|
||||
});
|
||||
|
||||
test('Wait for auction completion.', (done) => {
|
||||
@ -308,7 +299,7 @@ const providerAuctionTestsWithBids = (bidsAmount: number[], numProviders: number
|
||||
|
||||
// Filter bidders to exclude bids exceeding maxPrice
|
||||
const filteredBidders = sortedBidders.filter(bidder => {
|
||||
return parseInt(bidder.bid.reveal.bidAmount) <= parseInt(`${maxPrice.amount}${maxPrice.denom}`);
|
||||
return parseInt(bidder.bid.reveal.bidAmount) <= parseInt(`${maxPrice}${DENOM}`);
|
||||
});
|
||||
|
||||
const numWinners = Math.min(filteredBidders.length, numProviders);
|
||||
|
16
src/index.ts
16
src/index.ts
@ -23,8 +23,8 @@ import {
|
||||
import {
|
||||
MessageMsgCommitBid,
|
||||
MessageMsgRevealBid,
|
||||
MsgCreateProviderAuction,
|
||||
MsgCreateVickreyAuction
|
||||
MessageCreateVickreyAuction,
|
||||
MessageCreateProviderAuction
|
||||
} from './types/cerc/auction/message';
|
||||
import { MessageMsgSendCoins } from './types/cosmos/bank/message';
|
||||
import { MessageMsgOnboardParticipant } from './types/cerc/onboarding/message';
|
||||
@ -507,10 +507,11 @@ export class Registry {
|
||||
{
|
||||
commitsDuration,
|
||||
revealsDuration,
|
||||
denom,
|
||||
commitFee,
|
||||
revealFee,
|
||||
minimumBid
|
||||
}: MsgCreateVickreyAuction,
|
||||
}: MessageCreateVickreyAuction,
|
||||
privateKey: string,
|
||||
fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER
|
||||
): Promise<MsgCreateAuctionResponse> {
|
||||
@ -523,10 +524,11 @@ export class Registry {
|
||||
AUCTION_KIND_VICKREY,
|
||||
commitsDuration,
|
||||
revealsDuration,
|
||||
denom,
|
||||
commitFee,
|
||||
revealFee,
|
||||
minimumBid,
|
||||
undefined,
|
||||
'',
|
||||
0,
|
||||
fee
|
||||
);
|
||||
@ -536,11 +538,12 @@ export class Registry {
|
||||
{
|
||||
commitsDuration,
|
||||
revealsDuration,
|
||||
denom,
|
||||
commitFee,
|
||||
revealFee,
|
||||
maxPrice,
|
||||
numProviders
|
||||
}: MsgCreateProviderAuction,
|
||||
}: MessageCreateProviderAuction,
|
||||
privateKey: string,
|
||||
fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER
|
||||
): Promise<MsgCreateAuctionResponse> {
|
||||
@ -553,9 +556,10 @@ export class Registry {
|
||||
AUCTION_KIND_PROVIDER,
|
||||
commitsDuration,
|
||||
revealsDuration,
|
||||
denom,
|
||||
commitFee,
|
||||
revealFee,
|
||||
undefined,
|
||||
'',
|
||||
maxPrice,
|
||||
numProviders,
|
||||
fee
|
||||
|
@ -1,3 +1,4 @@
|
||||
import Long from 'long';
|
||||
|
||||
import { GeneratedType, OfflineSigner, Registry } from '@cosmjs/proto-signing';
|
||||
import {
|
||||
@ -418,12 +419,13 @@ export class LaconicClient extends SigningStargateClient {
|
||||
public async createAuction (
|
||||
signer: string,
|
||||
kind: string,
|
||||
commitsDuration: Duration,
|
||||
revealsDuration: Duration,
|
||||
commitFee: Coin,
|
||||
revealFee: Coin,
|
||||
minimumBid: Coin | undefined,
|
||||
maxPrice: Coin | undefined,
|
||||
commitsDuration: string,
|
||||
revealsDuration: string,
|
||||
denom: string,
|
||||
commitFee: string,
|
||||
revealFee: string,
|
||||
minimumBid: string,
|
||||
maxPrice: string,
|
||||
numProviders: number,
|
||||
fee: StdFee | 'auto' | number,
|
||||
memo = ''
|
||||
@ -433,12 +435,12 @@ export class LaconicClient extends SigningStargateClient {
|
||||
value: {
|
||||
signer,
|
||||
kind,
|
||||
commitsDuration,
|
||||
revealsDuration,
|
||||
commitFee,
|
||||
revealFee,
|
||||
minimumBid,
|
||||
maxPrice,
|
||||
commitsDuration: Duration.fromPartial({ seconds: Long.fromString(commitsDuration) }),
|
||||
revealsDuration: Duration.fromPartial({ seconds: Long.fromString(revealsDuration) }),
|
||||
commitFee: Coin.fromPartial({ amount: commitFee, denom }),
|
||||
revealFee: Coin.fromPartial({ amount: revealFee, denom }),
|
||||
minimumBid: Coin.fromPartial({ amount: minimumBid, denom }),
|
||||
maxPrice: Coin.fromPartial({ amount: maxPrice, denom }),
|
||||
numProviders
|
||||
}
|
||||
};
|
||||
|
@ -1,8 +1,6 @@
|
||||
import { EncodeObject, GeneratedType } from '@cosmjs/proto-signing';
|
||||
import { Coin } from '@cosmjs/amino';
|
||||
|
||||
import { MsgCommitBidResponse, MsgCommitBid, MsgRevealBid, MsgRevealBidResponse, MsgCreateAuction, MsgCreateAuctionResponse } from '../../../proto/cerc/auction/v1/tx';
|
||||
import { Duration } from '../../../proto/google/protobuf/duration';
|
||||
|
||||
export const typeUrlMsgCreateAuction = '/cerc.auction.v1.MsgCreateAuction';
|
||||
export const typeUrlMsgCommitBid = '/cerc.auction.v1.MsgCommitBid';
|
||||
@ -45,19 +43,21 @@ export interface MessageMsgRevealBid {
|
||||
reveal: string,
|
||||
}
|
||||
|
||||
export interface MsgCreateVickreyAuction {
|
||||
commitsDuration: Duration;
|
||||
revealsDuration: Duration;
|
||||
commitFee: Coin;
|
||||
revealFee: Coin;
|
||||
minimumBid: Coin;
|
||||
export interface MessageCreateVickreyAuction {
|
||||
commitsDuration: string;
|
||||
revealsDuration: string;
|
||||
denom: string;
|
||||
commitFee: string;
|
||||
revealFee: string;
|
||||
minimumBid: string;
|
||||
}
|
||||
|
||||
export interface MsgCreateProviderAuction {
|
||||
commitsDuration: Duration;
|
||||
revealsDuration: Duration;
|
||||
commitFee: Coin;
|
||||
revealFee: Coin;
|
||||
maxPrice: Coin;
|
||||
export interface MessageCreateProviderAuction {
|
||||
commitsDuration: string;
|
||||
revealsDuration: string;
|
||||
denom: string;
|
||||
commitFee: string;
|
||||
revealFee: string;
|
||||
maxPrice: string;
|
||||
numProviders: number;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user