Add methods for creating auctions and add auction tests #28
@ -1,31 +1,31 @@
|
||||
import Long from 'long';
|
||||
|
||||
import { coin } from '@cosmjs/amino';
|
||||
|
||||
import { Registry, Account, createBid } from './index';
|
||||
import { getConfig } from './testing/helper';
|
||||
import { DENOM, DURATION } from './constants';
|
||||
import { DENOM } from './constants';
|
||||
import { Duration } from './proto/google/protobuf/duration';
|
||||
|
||||
jest.setTimeout(30 * 60 * 1000);
|
||||
const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
||||
|
||||
const commitsDuration = {
|
||||
seconds: Long.fromNumber(DURATION),
|
||||
const duration = 60;
|
||||
|
||||
const commitsDuration = Duration.fromPartial({
|
||||
seconds: Long.fromNumber(duration),
|
||||
nanos: 0
|
||||
};
|
||||
|
||||
const revealsDuration = {
|
||||
seconds: Long.fromNumber(DURATION),
|
||||
});
|
||||
const revealsDuration = Duration.fromPartial({
|
||||
seconds: Long.fromNumber(duration),
|
||||
nanos: 0
|
||||
};
|
||||
});
|
||||
|
||||
const commitFee = {
|
||||
denom: DENOM,
|
||||
amount: '1000'
|
||||
};
|
||||
const commitFee = coin('1000', DENOM);
|
||||
const revealFee = coin('1000', DENOM);
|
||||
|
||||
const revealFee = {
|
||||
denom: DENOM,
|
||||
amount: '1000'
|
||||
};
|
||||
const creatorInitialBalance = 1000000000000;
|
||||
const bidderInitialBalance = 20000000;
|
||||
|
||||
const createAuctionTests = () => {
|
||||
let registry: Registry;
|
||||
@ -37,15 +37,13 @@ const createAuctionTests = () => {
|
||||
let bidAmounts: { type: string, quantity: string }[] = [];
|
||||
|
||||
beforeAll(async () => {
|
||||
console.log('Running vickrey auction tests');
|
||||
|
||||
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||
|
||||
// Create auction creator account
|
||||
const mnenonic1 = Account.generateMnemonic();
|
||||
const auctionCreator = await Account.generateFromMnemonic(mnenonic1);
|
||||
await auctionCreator.init();
|
||||
await registry.sendCoins({ denom: DENOM, amount: '1000000000000', destinationAddress: auctionCreator.address }, privateKey, fee);
|
||||
await registry.sendCoins({ denom: DENOM, amount: creatorInitialBalance.toString(), destinationAddress: auctionCreator.address }, privateKey, fee);
|
||||
auctionCreatorAccount = { address: auctionCreator.address, privateKey: auctionCreator.privateKey.toString('hex') };
|
||||
});
|
||||
|
||||
@ -54,7 +52,7 @@ const createAuctionTests = () => {
|
||||
const mnenonic = Account.generateMnemonic();
|
||||
const account = await Account.generateFromMnemonic(mnenonic);
|
||||
await account.init();
|
||||
await registry.sendCoins({ denom: DENOM, amount: '20000000', destinationAddress: account.address }, privateKey, fee);
|
||||
await registry.sendCoins({ denom: DENOM, amount: bidderInitialBalance.toString(), destinationAddress: account.address }, privateKey, fee);
|
||||
bidderAccounts.push({ address: account.address, privateKey: account.privateKey.toString('hex') });
|
||||
}
|
||||
});
|
||||
@ -70,8 +68,7 @@ const createAuctionTests = () => {
|
||||
revealsDuration,
|
||||
commitFee,
|
||||
revealFee,
|
||||
minimumBid,
|
||||
signer: auctionCreatorAccount.address
|
||||
minimumBid
|
||||
},
|
||||
auctionCreatorAccount.privateKey, fee);
|
||||
|
||||
@ -98,7 +95,7 @@ const createAuctionTests = () => {
|
||||
});
|
||||
|
||||
test('Wait for reveal phase.', (done) => {
|
||||
const commitTime = DURATION * 1000;
|
||||
const commitTime = duration * 1000;
|
||||
const waitTime = commitTime + (6 * 1000);
|
||||
|
||||
setTimeout(done, waitTime);
|
||||
@ -125,7 +122,7 @@ const createAuctionTests = () => {
|
||||
});
|
||||
|
||||
test('Wait for auction completion.', (done) => {
|
||||
const revealTime = DURATION * 1000;
|
||||
const revealTime = duration * 1000;
|
||||
const waitTime = revealTime + (6 * 1000);
|
||||
|
||||
setTimeout(done, waitTime);
|
||||
@ -136,13 +133,12 @@ const createAuctionTests = () => {
|
||||
expect(auction.status).toEqual('completed');
|
||||
|
||||
const highestBidder = bidderAccounts[bidderAccounts.length - 1];
|
||||
const secondHighestBidder = (bidderAccounts.length > 1 ? bidderAccounts[bidderAccounts.length - 2] : highestBidder);
|
||||
const secondHighestBidder = (bidderAccounts[bidderAccounts.length - 2]);
|
||||
|
||||
expect(auction.winnerAddresses[0]).toEqual(highestBidder.address);
|
||||
expect(highestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerBids[0].quantity}${auction.winnerBids[0].type}`);
|
||||
expect(secondHighestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`);
|
||||
|
||||
const bidderInitialBalance = 20000000;
|
||||
const winningPriceAmount = parseInt(auction.winnerPrice.quantity, 10);
|
||||
const expectedBalance = (bidderInitialBalance - winningPriceAmount).toString();
|
||||
|
||||
@ -167,15 +163,13 @@ const createProviderAuctionTests = () => {
|
||||
let bidAmounts: { type: string, quantity: string }[] = [];
|
||||
|
||||
beforeAll(async () => {
|
||||
console.log('Running provider auction tests');
|
||||
|
||||
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||
|
||||
// Create auction creator account
|
||||
const mnenonic1 = Account.generateMnemonic();
|
||||
const auctionCreator = await Account.generateFromMnemonic(mnenonic1);
|
||||
await auctionCreator.init();
|
||||
await registry.sendCoins({ denom: DENOM, amount: '1000000000000', destinationAddress: auctionCreator.address }, privateKey, fee);
|
||||
await registry.sendCoins({ denom: DENOM, amount: creatorInitialBalance.toString(), destinationAddress: auctionCreator.address }, privateKey, fee);
|
||||
auctionCreatorAccount = { address: auctionCreator.address, privateKey: auctionCreator.privateKey.toString('hex') };
|
||||
});
|
||||
|
||||
@ -184,7 +178,7 @@ const createProviderAuctionTests = () => {
|
||||
const mnenonic = Account.generateMnemonic();
|
||||
const account = await Account.generateFromMnemonic(mnenonic);
|
||||
await account.init();
|
||||
await registry.sendCoins({ denom: DENOM, amount: '20000000', destinationAddress: account.address }, privateKey, fee);
|
||||
await registry.sendCoins({ denom: DENOM, amount: bidderInitialBalance.toString(), destinationAddress: account.address }, privateKey, fee);
|
||||
bidderAccounts.push({ address: account.address, privateKey: account.privateKey.toString('hex') });
|
||||
}
|
||||
});
|
||||
@ -200,7 +194,6 @@ const createProviderAuctionTests = () => {
|
||||
revealsDuration,
|
||||
commitFee,
|
||||
revealFee,
|
||||
signer: auctionCreatorAccount.address,
|
||||
maxPrice,
|
||||
numProviders: 3
|
||||
},
|
||||
@ -229,7 +222,7 @@ const createProviderAuctionTests = () => {
|
||||
});
|
||||
|
||||
test('Wait for reveal phase.', (done) => {
|
||||
const commitTime = DURATION * 1000;
|
||||
const commitTime = duration * 1000;
|
||||
const waitTime = commitTime + (6 * 1000);
|
||||
|
||||
setTimeout(done, waitTime);
|
||||
@ -256,7 +249,7 @@ const createProviderAuctionTests = () => {
|
||||
});
|
||||
|
||||
test('Wait for auction completion.', (done) => {
|
||||
const revealTime = DURATION * 1000;
|
||||
const revealTime = duration * 1000;
|
||||
const waitTime = revealTime + (6 * 1000);
|
||||
|
||||
setTimeout(done, waitTime);
|
||||
@ -275,8 +268,6 @@ const createProviderAuctionTests = () => {
|
||||
|
||||
expect(winner.bid.reveal.bidAmount).toEqual(`${auction.winnerBids[i].quantity}${auction.winnerBids[i].type}`);
|
||||
|
||||
const bidderInitialBalance = 20000000;
|
||||
|
||||
const [winnerAccountObj] = await registry.getAccounts([winner.address]);
|
||||
expect(winnerAccountObj).toBeDefined();
|
||||
expect(winnerAccountObj.address).toBe(winner.address);
|
||||
@ -296,7 +287,6 @@ const createProviderAuctionTests = () => {
|
||||
|
||||
const [{ type, quantity: currentBalance }] = creatorAccountObj.balance;
|
||||
|
||||
const creatorInitialBalance = 1000000000000;
|
||||
const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10);
|
||||
const expectedBalance = creatorInitialBalance - (winningBidAmount * 3);
|
||||
|
||||
|
@ -97,7 +97,7 @@ const auctionTests = (numBidders = 3) => {
|
||||
const highestBidder = accounts[accounts.length - 1];
|
||||
const secondHighestBidder = (accounts.length > 1 ? accounts[accounts.length - 2] : highestBidder);
|
||||
|
||||
expect(auction.winnerAddress).toEqual(highestBidder.address);
|
||||
expect(auction.winnerAddresses[0]).toEqual(highestBidder.address);
|
||||
expect(highestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerBid.quantity}${auction.winnerBid.type}`);
|
||||
expect(secondHighestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`);
|
||||
|
||||
|
@ -1,3 +1,2 @@
|
||||
export const DENOM = 'alnt';
|
||||
export const DURATION = 60;
|
||||
export const DEFAULT_GAS_ESTIMATION_MULTIPLIER = 2;
|
||||
|
Loading…
Reference in New Issue
Block a user