Check auction creator balance in provider auction
This commit is contained in:
parent
216199fe47
commit
14ee5d547f
@ -40,7 +40,7 @@ message Params {
|
|||||||
(gogoproto.moretags) = "json:\"reveal_fee\" yaml:\"reveal_fee\""
|
(gogoproto.moretags) = "json:\"reveal_fee\" yaml:\"reveal_fee\""
|
||||||
];
|
];
|
||||||
|
|
||||||
// Minimum acceptable bid amount
|
// Minimum acceptable bid amount (for vickrey auctions)
|
||||||
cosmos.base.v1beta1.Coin minimum_bid = 5 [
|
cosmos.base.v1beta1.Coin minimum_bid = 5 [
|
||||||
(gogoproto.nullable) = false,
|
(gogoproto.nullable) = false,
|
||||||
(gogoproto.moretags) = "json:\"minimum_bid\" yaml:\"minimum_bid\""
|
(gogoproto.moretags) = "json:\"minimum_bid\" yaml:\"minimum_bid\""
|
||||||
@ -54,9 +54,7 @@ message Auction {
|
|||||||
string id = 1;
|
string id = 1;
|
||||||
|
|
||||||
// Auction's kind (vickrey | provider)
|
// Auction's kind (vickrey | provider)
|
||||||
string kind = 2 [
|
string kind = 2 [ (gogoproto.moretags) = "json:\"kind\" yaml:\"kind\"" ];
|
||||||
(gogoproto.moretags) = "json:\"kind\" yaml:\"kind\""
|
|
||||||
];
|
|
||||||
|
|
||||||
string status = 3;
|
string status = 3;
|
||||||
|
|
||||||
@ -95,13 +93,13 @@ message Auction {
|
|||||||
(gogoproto.moretags) = "json:\"reveal_fee\" yaml:\"reveal_fee\""
|
(gogoproto.moretags) = "json:\"reveal_fee\" yaml:\"reveal_fee\""
|
||||||
];
|
];
|
||||||
|
|
||||||
// Minimum acceptable bid amount for a valid commit
|
// Minimum acceptable bid amount for a valid commit (for vickrey auctions)
|
||||||
cosmos.base.v1beta1.Coin minimum_bid = 10 [
|
cosmos.base.v1beta1.Coin minimum_bid = 10 [
|
||||||
(gogoproto.nullable) = false,
|
(gogoproto.nullable) = false,
|
||||||
(gogoproto.moretags) = "json:\"minimum_bid\" yaml:\"minimum_bid\""
|
(gogoproto.moretags) = "json:\"minimum_bid\" yaml:\"minimum_bid\""
|
||||||
];
|
];
|
||||||
|
|
||||||
// Addresses of the winners (one for vickrey auctions and can be multiple for provider auctions)
|
// Winner's address for Vickrey auctions, can be multiple for provider auctions
|
||||||
repeated string winner_addresses = 11;
|
repeated string winner_addresses = 11;
|
||||||
|
|
||||||
// Winning bids, i.e., the best bids
|
// Winning bids, i.e., the best bids
|
||||||
@ -110,13 +108,13 @@ message Auction {
|
|||||||
(gogoproto.moretags) = "json:\"winning_bids\" yaml:\"winning_bids\""
|
(gogoproto.moretags) = "json:\"winning_bids\" yaml:\"winning_bids\""
|
||||||
];
|
];
|
||||||
|
|
||||||
// Amount the winner pays, i.e. the second best bid
|
// Amount the winner pays (vickrey auction) or is paid (provider auction)
|
||||||
cosmos.base.v1beta1.Coin winning_price = 13 [
|
cosmos.base.v1beta1.Coin winning_price = 13 [
|
||||||
(gogoproto.nullable) = false,
|
(gogoproto.nullable) = false,
|
||||||
(gogoproto.moretags) = "json:\"winning_price\" yaml:\"winning_price\""
|
(gogoproto.moretags) = "json:\"winning_price\" yaml:\"winning_price\""
|
||||||
];
|
];
|
||||||
|
|
||||||
// Maximum acceptable bid amount for a valid commit for service provider auctions
|
// Maximum acceptable bid amount (for provider auctions)
|
||||||
cosmos.base.v1beta1.Coin max_price = 14 [
|
cosmos.base.v1beta1.Coin max_price = 14 [
|
||||||
(gogoproto.nullable) = false,
|
(gogoproto.nullable) = false,
|
||||||
(gogoproto.moretags) = "json:\"max_price\" yaml:\"max_price\""
|
(gogoproto.moretags) = "json:\"max_price\" yaml:\"max_price\""
|
||||||
|
@ -67,7 +67,7 @@ message MsgCreateAuction {
|
|||||||
(gogoproto.moretags) = "json:\"reveal_fee\" yaml:\"reveal_fee\""
|
(gogoproto.moretags) = "json:\"reveal_fee\" yaml:\"reveal_fee\""
|
||||||
];
|
];
|
||||||
|
|
||||||
// Minimum acceptable bid amount
|
// Minimum acceptable bid amount (for vickrey auctions)
|
||||||
cosmos.base.v1beta1.Coin minimum_bid = 5 [
|
cosmos.base.v1beta1.Coin minimum_bid = 5 [
|
||||||
(gogoproto.nullable) = false,
|
(gogoproto.nullable) = false,
|
||||||
(gogoproto.moretags) = "json:\"minimum_bid\" yaml:\"minimum_bid\""
|
(gogoproto.moretags) = "json:\"minimum_bid\" yaml:\"minimum_bid\""
|
||||||
@ -78,11 +78,9 @@ message MsgCreateAuction {
|
|||||||
[ (gogoproto.moretags) = "json:\"signer\" yaml:\"signer\"" ];
|
[ (gogoproto.moretags) = "json:\"signer\" yaml:\"signer\"" ];
|
||||||
|
|
||||||
// Auction's kind (vickrey | provider)
|
// Auction's kind (vickrey | provider)
|
||||||
string kind = 7 [
|
string kind = 7 [ (gogoproto.moretags) = "json:\"kind\" yaml:\"kind\"" ];
|
||||||
(gogoproto.moretags) = "json:\"kind\" yaml:\"kind\""
|
|
||||||
];
|
|
||||||
|
|
||||||
// Maximum acceptable bid amount (for service provider auctions)
|
// Maximum acceptable bid amount (for provider auctions)
|
||||||
cosmos.base.v1beta1.Coin max_price = 8 [
|
cosmos.base.v1beta1.Coin max_price = 8 [
|
||||||
(gogoproto.nullable) = false,
|
(gogoproto.nullable) = false,
|
||||||
(gogoproto.moretags) = "json:\"max_price\" yaml:\"max_price\""
|
(gogoproto.moretags) = "json:\"max_price\" yaml:\"max_price\""
|
||||||
|
@ -122,7 +122,7 @@ const createAuctionTests = () => {
|
|||||||
setTimeout(done, waitTime);
|
setTimeout(done, waitTime);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Check auction winner, status, and balance.', async () => {
|
test('Check auction winner, status, and winner balance.', async () => {
|
||||||
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
||||||
expect(auction.status).toEqual('completed');
|
expect(auction.status).toEqual('completed');
|
||||||
|
|
||||||
@ -133,10 +133,9 @@ const createAuctionTests = () => {
|
|||||||
expect(highestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerBids[0].quantity}${auction.winnerBids[0].type}`);
|
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}`);
|
expect(secondHighestBidder.bid.reveal.bidAmount).toEqual(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`);
|
||||||
|
|
||||||
const initialBalance = 20000000;
|
const bidderInitialBalance = 20000000;
|
||||||
const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10);
|
const winningPriceAmount = parseInt(auction.winnerPrice.quantity, 10);
|
||||||
|
const expectedBalance = (bidderInitialBalance - winningPriceAmount).toString();
|
||||||
const expectedBalance = (initialBalance - winningBidAmount).toString();
|
|
||||||
|
|
||||||
const [winnerAccountObj] = await registry.getAccounts([highestBidder.address]);
|
const [winnerAccountObj] = await registry.getAccounts([highestBidder.address]);
|
||||||
expect(winnerAccountObj).toBeDefined();
|
expect(winnerAccountObj).toBeDefined();
|
||||||
@ -149,7 +148,7 @@ const createAuctionTests = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const createSPAuctionTests = () => {
|
const createProviderAuctionTests = () => {
|
||||||
let registry: Registry;
|
let registry: Registry;
|
||||||
let auctionId: string;
|
let auctionId: string;
|
||||||
|
|
||||||
@ -159,7 +158,7 @@ const createSPAuctionTests = () => {
|
|||||||
let bidAmounts: { type: string, quantity: string }[] = [];
|
let bidAmounts: { type: string, quantity: string }[] = [];
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
console.log('Running service provider auction tests');
|
console.log('Running provider auction tests');
|
||||||
|
|
||||||
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
@ -181,7 +180,7 @@ const createSPAuctionTests = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Create service provider auction', async () => {
|
test('Create provider auction', async () => {
|
||||||
const maxPrice = {
|
const maxPrice = {
|
||||||
denom: 'alnt',
|
denom: 'alnt',
|
||||||
amount: '100000000'
|
amount: '100000000'
|
||||||
@ -245,7 +244,7 @@ const createSPAuctionTests = () => {
|
|||||||
setTimeout(done, waitTime);
|
setTimeout(done, waitTime);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Check auction winner, status, and balance.', async () => {
|
test('Check auction winner, status, and bidder balance.', async () => {
|
||||||
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
||||||
expect(auction.status).toEqual('completed');
|
expect(auction.status).toEqual('completed');
|
||||||
|
|
||||||
@ -258,23 +257,35 @@ const createSPAuctionTests = () => {
|
|||||||
|
|
||||||
expect(winner.bid.reveal.bidAmount).toEqual(`${auction.winnerBids[i].quantity}${auction.winnerBids[i].type}`);
|
expect(winner.bid.reveal.bidAmount).toEqual(`${auction.winnerBids[i].quantity}${auction.winnerBids[i].type}`);
|
||||||
|
|
||||||
const initialBalance = 20000000;
|
const bidderInitialBalance = 20000000;
|
||||||
|
|
||||||
const [winnerAccountObj] = await registry.getAccounts([winner.address]);
|
const [winnerAccountObj] = await registry.getAccounts([winner.address]);
|
||||||
expect(winnerAccountObj).toBeDefined();
|
expect(winnerAccountObj).toBeDefined();
|
||||||
expect(winnerAccountObj.address).toBe(winner.address);
|
expect(winnerAccountObj.address).toBe(winner.address);
|
||||||
|
|
||||||
const [{ type, quantity: currentBalance }] = winnerAccountObj.balance;
|
const [{ type, quantity: currentBalance }] = winnerAccountObj.balance;
|
||||||
expect(type).toBe(DENOM);
|
|
||||||
|
|
||||||
const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10);
|
const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10);
|
||||||
|
const expectedBalance = bidderInitialBalance + winningBidAmount;
|
||||||
|
|
||||||
const expectedBalance = (parseInt(currentBalance, 10) + winningBidAmount).toString();
|
expect(type).toBe(DENOM);
|
||||||
|
expect(currentBalance).toEqual(expectedBalance);
|
||||||
expect(expectedBalance).toEqual(initialBalance.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const [creatorAccountObj] = await registry.getAccounts([auctionCreatorAccount.address]);
|
||||||
|
expect(creatorAccountObj).toBeDefined();
|
||||||
|
expect(creatorAccountObj.address).toBe(auctionCreatorAccount.address);
|
||||||
|
|
||||||
|
const [{ type, quantity: currentBalance }] = creatorAccountObj.balance;
|
||||||
|
|
||||||
|
const creatorInitialBalance = 1000000000000;
|
||||||
|
const winningBidAmount = parseInt(auction.winnerPrice.quantity, 10);
|
||||||
|
const expectedBalance = creatorInitialBalance - (winningBidAmount * 3);
|
||||||
|
|
||||||
|
expect(type).toBe(DENOM);
|
||||||
|
expect(currentBalance).toEqual(expectedBalance);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('Vickrey Auction', () => createAuctionTests());
|
describe('Vickrey Auction', () => createAuctionTests());
|
||||||
describe('Service provider Auction', () => createSPAuctionTests());
|
describe('Provider Auction', () => createProviderAuctionTests());
|
||||||
|
Loading…
Reference in New Issue
Block a user