Skip to content

Commit

Permalink
fix: Represent the Escrow Address as bytes (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
keefertaylor authored Jul 12, 2023
1 parent f64401a commit 2737606
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 126 deletions.
36 changes: 19 additions & 17 deletions api/pob/builder/v1/genesis.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/pob/builder/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ message Params {

// escrow_account_address is the address of the account that will receive a
// portion of the bid proceeds.
string escrow_account_address = 2;
bytes escrow_account_address = 2;

// reserve_fee specifies the bid floor for the auction.
cosmos.base.v1beta1.Coin reserve_fee = 3
Expand Down
5 changes: 4 additions & 1 deletion tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ func (s *IntegrationTestSuite) initNodes() {
val0ConfigDir := s.chain.validators[0].configDir()

// Define the builder module parameters
escrowAddress, err := sdk.AccAddressFromBech32("cosmos14j5j2lsx7629590jvpk3vj0xe9w8203jf4yknk")
s.Require().Nil(err, "Unexpected error decoding escrow address")

params := types.Params{
MaxBundleSize: 5,
EscrowAccountAddress: "cosmos14j5j2lsx7629590jvpk3vj0xe9w8203jf4yknk",
EscrowAccountAddress: escrowAddress,
ReserveFee: sdk.NewCoin(app.BondDenom, sdk.NewInt(1000000)),
MinBidIncrement: sdk.NewCoin(app.BondDenom, sdk.NewInt(1000000)),
ProposerFee: sdk.NewDecWithPrec(1, 2),
Expand Down
52 changes: 26 additions & 26 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *IntegrationTestSuite) TestValidBids() {
name: "Valid auction bid",
test: func() {
// Get escrow account balance to ensure that it is updated correctly
escrowBalance := s.queryBalanceOf(escrowAddress, app.BondDenom)
escrowBalance := s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom)

// Create a bundle with a single transaction
bundle := [][]byte{
Expand All @@ -72,14 +72,14 @@ func (s *IntegrationTestSuite) TestValidBids() {

// Ensure that the escrow account has the correct balance
expectedEscrowFee := s.calculateProposerEscrowSplit(bid)
s.Require().Equal(escrowBalance.Add(expectedEscrowFee), s.queryBalanceOf(escrowAddress, app.BondDenom))
s.Require().Equal(escrowBalance.Add(expectedEscrowFee), s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom))
},
},
{
name: "Valid bid with multiple other transactions",
test: func() {
// Get escrow account balance to ensure that it is updated correctly
escrowBalance := s.queryBalanceOf(escrowAddress, app.BondDenom)
escrowBalance := s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom)

// Create a bundle with a multiple transaction that is valid
bundle := make([][]byte, maxBundleSize)
Expand Down Expand Up @@ -128,14 +128,14 @@ func (s *IntegrationTestSuite) TestValidBids() {

// Ensure that the escrow account has the correct balance
expectedEscrowFee := s.calculateProposerEscrowSplit(bid)
s.Require().Equal(escrowBalance.Add(expectedEscrowFee), s.queryBalanceOf(escrowAddress, app.BondDenom))
s.Require().Equal(escrowBalance.Add(expectedEscrowFee), s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom))
},
},
{
name: "iterative bidding from the same account",
test: func() {
// Get escrow account balance to ensure that it is updated correctly
escrowBalance := s.queryBalanceOf(escrowAddress, app.BondDenom)
escrowBalance := s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom)

// Create a bundle with a multiple transaction that is valid
bundle := make([][]byte, maxBundleSize)
Expand Down Expand Up @@ -187,14 +187,14 @@ func (s *IntegrationTestSuite) TestValidBids() {

// Ensure that the escrow account has the correct balance
expectedEscrowFee := s.calculateProposerEscrowSplit(bid3)
s.Require().Equal(escrowBalance.Add(expectedEscrowFee), s.queryBalanceOf(escrowAddress, app.BondDenom))
s.Require().Equal(escrowBalance.Add(expectedEscrowFee), s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom))
},
},
{
name: "bid with a bundle with transactions that are already in the mempool",
test: func() {
// Get escrow account balance to ensure that it is updated correctly
escrowBalance := s.queryBalanceOf(escrowAddress, app.BondDenom)
escrowBalance := s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom)

// Create a bundle with a multiple transaction that is valid
bundle := make([][]byte, maxBundleSize)
Expand Down Expand Up @@ -247,14 +247,14 @@ func (s *IntegrationTestSuite) TestValidBids() {

// Ensure that the escrow account has the correct balance
expectedEscrowFee := s.calculateProposerEscrowSplit(bid)
s.Require().Equal(escrowBalance.Add(expectedEscrowFee), s.queryBalanceOf(escrowAddress, app.BondDenom))
s.Require().Equal(escrowBalance.Add(expectedEscrowFee), s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom))
},
},
{
name: "searcher attempts to include several txs in the same block to invalidate auction (we extract bid regardless)",
test: func() {
// Get escrow account balance to ensure that it is updated correctly
escrowBalance := s.queryBalanceOf(escrowAddress, app.BondDenom)
escrowBalance := s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom)

// Create a bundle with a multiple transaction that is valid
bundle := make([][]byte, maxBundleSize)
Expand Down Expand Up @@ -306,7 +306,7 @@ func (s *IntegrationTestSuite) TestValidBids() {

// Ensure that the escrow account has the correct balance
expectedEscrowFee := s.calculateProposerEscrowSplit(bid)
s.Require().Equal(escrowBalance.Add(expectedEscrowFee), s.queryBalanceOf(escrowAddress, app.BondDenom))
s.Require().Equal(escrowBalance.Add(expectedEscrowFee), s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom))
},
},
}
Expand Down Expand Up @@ -351,7 +351,7 @@ func (s *IntegrationTestSuite) TestMultipleBids() {
name: "broadcasting bids to two different validators (both should execute over several blocks) with same bid",
test: func() {
// Get escrow account balance to ensure that it is updated correctly
escrowBalance := s.queryBalanceOf(escrowAddress, app.BondDenom)
escrowBalance := s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom)

// Create a bundle with a multiple transaction that is valid
bundle := make([][]byte, maxBundleSize)
Expand Down Expand Up @@ -409,14 +409,14 @@ func (s *IntegrationTestSuite) TestMultipleBids() {

// Ensure that the escrow account has the correct balance (both bids should have been extracted by this point)
expectedEscrowFee := s.calculateProposerEscrowSplit(bid).Add(s.calculateProposerEscrowSplit(bid2))
s.Require().Equal(escrowBalance.Add(expectedEscrowFee), s.queryBalanceOf(escrowAddress, app.BondDenom))
s.Require().Equal(escrowBalance.Add(expectedEscrowFee), s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom))
},
},
{
name: "multi-block auction bids with different bids",
test: func() {
// Get escrow account balance to ensure that it is updated correctly
escrowBalance := s.queryBalanceOf(escrowAddress, app.BondDenom)
escrowBalance := s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom)

// Create a bundle with a multiple transaction that is valid
bundle := make([][]byte, maxBundleSize)
Expand Down Expand Up @@ -477,14 +477,14 @@ func (s *IntegrationTestSuite) TestMultipleBids() {

// Ensure that the escrow account has the correct balance (both bids should have been extracted by this point)
expectedEscrowFee := s.calculateProposerEscrowSplit(bid).Add(s.calculateProposerEscrowSplit(bid2))
s.Require().Equal(escrowBalance.Add(expectedEscrowFee), s.queryBalanceOf(escrowAddress, app.BondDenom))
s.Require().Equal(escrowBalance.Add(expectedEscrowFee), s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom))
},
},
{
name: "Multiple bid transactions with second bid being smaller than min bid increment (same account)",
test: func() {
// Get escrow account balance
escrowBalance := s.queryBalanceOf(escrowAddress, app.BondDenom)
escrowBalance := s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom)

// Create a bundle with a single transaction
bundle := [][]byte{
Expand Down Expand Up @@ -519,7 +519,7 @@ func (s *IntegrationTestSuite) TestMultipleBids() {

// Ensure that the escrow account has the correct balance
expectedEscrowFee := s.calculateProposerEscrowSplit(bid)
s.Require().Equal(expectedEscrowFee.Add(escrowBalance), s.queryBalanceOf(escrowAddress, app.BondDenom))
s.Require().Equal(expectedEscrowFee.Add(escrowBalance), s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom))

// Wait another block to make sure the second bid is not executed
s.waitForABlock()
Expand All @@ -530,7 +530,7 @@ func (s *IntegrationTestSuite) TestMultipleBids() {
name: "Multiple transactions with second bid being smaller than min bid increment (different account)",
test: func() {
// Get escrow account balance
escrowBalance := s.queryBalanceOf(escrowAddress, app.BondDenom)
escrowBalance := s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom)

// Create a bundle with a single transaction
bundle := [][]byte{
Expand Down Expand Up @@ -565,7 +565,7 @@ func (s *IntegrationTestSuite) TestMultipleBids() {

// Ensure that the escrow account has the correct balance
expectedEscrowFee := s.calculateProposerEscrowSplit(bid)
s.Require().Equal(expectedEscrowFee.Add(escrowBalance), s.queryBalanceOf(escrowAddress, app.BondDenom))
s.Require().Equal(expectedEscrowFee.Add(escrowBalance), s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom))

// Wait another block to make sure the second bid is not executed
s.waitForABlock()
Expand All @@ -576,7 +576,7 @@ func (s *IntegrationTestSuite) TestMultipleBids() {
name: "Multiple transactions with increasing bids but first bid has same bundle so it should fail in later block (same account)",
test: func() {
// Get escrow account balance
escrowBalance := s.queryBalanceOf(escrowAddress, app.BondDenom)
escrowBalance := s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom)

// Create a bundle with a single transaction
bundle := [][]byte{
Expand Down Expand Up @@ -611,7 +611,7 @@ func (s *IntegrationTestSuite) TestMultipleBids() {

// Ensure that the escrow account has the correct balance
expectedEscrowFee := s.calculateProposerEscrowSplit(bid2)
s.Require().Equal(expectedEscrowFee.Add(escrowBalance), s.queryBalanceOf(escrowAddress, app.BondDenom))
s.Require().Equal(expectedEscrowFee.Add(escrowBalance), s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom))

// Wait for a block to be created and ensure that the first bid was not executed
s.waitForABlock()
Expand All @@ -622,7 +622,7 @@ func (s *IntegrationTestSuite) TestMultipleBids() {
name: "Multiple transactions with increasing bids but first bid has same bundle so it should fail in later block (different account)",
test: func() {
// Get escrow account balance
escrowBalance := s.queryBalanceOf(escrowAddress, app.BondDenom)
escrowBalance := s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom)

// Create a bundle with a single transaction
bundle := [][]byte{
Expand Down Expand Up @@ -657,7 +657,7 @@ func (s *IntegrationTestSuite) TestMultipleBids() {

// Ensure that the escrow account has the correct balance
expectedEscrowFee := s.calculateProposerEscrowSplit(bid2)
s.Require().Equal(expectedEscrowFee.Add(escrowBalance), s.queryBalanceOf(escrowAddress, app.BondDenom))
s.Require().Equal(expectedEscrowFee.Add(escrowBalance), s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom))

// Wait for a block to be created and ensure that the first bid was not executed
s.waitForABlock()
Expand All @@ -668,7 +668,7 @@ func (s *IntegrationTestSuite) TestMultipleBids() {
name: "Multiple transactions with increasing bids and different bundles (one should execute)",
test: func() {
// Get escrow account balance
escrowBalance := s.queryBalanceOf(escrowAddress, app.BondDenom)
escrowBalance := s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom)

// Create a bundle with a single transaction
firstBundle := [][]byte{
Expand Down Expand Up @@ -709,7 +709,7 @@ func (s *IntegrationTestSuite) TestMultipleBids() {

// Ensure that the escrow account has the correct balance
expectedEscrowFee := s.calculateProposerEscrowSplit(bid2)
s.Require().Equal(expectedEscrowFee.Add(escrowBalance), s.queryBalanceOf(escrowAddress, app.BondDenom))
s.Require().Equal(expectedEscrowFee.Add(escrowBalance), s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom))

// Wait for a block to be created and ensure that the second bid is executed
s.waitForABlock()
Expand Down Expand Up @@ -992,13 +992,13 @@ func (s *IntegrationTestSuite) TestInvalidBids() {
}

for _, tc := range testCases {
escrowBalance := s.queryBalanceOf(escrowAddress, app.BondDenom)
escrowBalance := s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom)

// Wait for a block to be created and run the test
s.waitForABlock()
s.Run(tc.name, tc.test)

// Get escrow account balance to ensure that it is not changed
s.Require().Equal(escrowBalance, s.queryBalanceOf(escrowAddress, app.BondDenom))
s.Require().Equal(escrowBalance, s.queryBalanceOf(sdk.AccAddress(escrowAddress).String(), app.BondDenom))
}
}
2 changes: 1 addition & 1 deletion x/builder/keeper/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (suite *KeeperTestSuite) TestValidateBidInfo() {
params := buildertypes.Params{
MaxBundleSize: maxBundleSize,
ReserveFee: reserveFee,
EscrowAccountAddress: escrowAddress.String(),
EscrowAccountAddress: escrowAddress,
FrontRunningProtection: frontRunningProtection,
MinBidIncrement: minBidIncrement,
}
Expand Down
Loading

0 comments on commit 2737606

Please sign in to comment.