Skip to content

Commit

Permalink
Merge pull request #134 from bnb-chain/develop
Browse files Browse the repository at this point in the history
release: draft release v0.0.10
  • Loading branch information
unclezoro authored Mar 24, 2023
2 parents 008354e + 2afaf23 commit 72baa3a
Show file tree
Hide file tree
Showing 183 changed files with 10,287 additions and 4,559 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## v0.0.10
* [\#136](https://github.com/bnb-chain/greenfield/pull/136)fix: forbid a stream account with negative static balance to pay
* [\#135](https://github.com/bnb-chain/greenfield/pull/135)modify default to inherit
* [\#132](https://github.com/bnb-chain/greenfield/pull/132) feat: allow unordered attestations
* [\#131](https://github.com/bnb-chain/greenfield/pull/131) feat: support delete bucket with non-zero charged read quota
* [\#108](https://github.com/bnb-chain/greenfield/pull/108) chore: refine storage module
* [\#126](https://github.com/bnb-chain/greenfield/pull/126) chore: refine permission module
* [\#125](https://github.com/bnb-chain/greenfield/pull/125) chore: refine bridge module
* [\#124](https://github.com/bnb-chain/greenfield/pull/124) feat: The visibility property of the Bucket&Object can be modified
* [\#112](https://github.com/bnb-chain/greenfield/pull/115) chore: refine sp module
* [\#129](https://github.com/bnb-chain/greenfield/pull/129) chore: refine payment module
* [\#117](https://github.com/bnb-chain/greenfield/pull/117) feat: implement validator tax in storage payment
* [\#116](https://github.com/bnb-chain/greenfield/pull/116) Merge pull request #116 from bnb-chain/refine_challenge
* [\#130](https://github.com/bnb-chain/greenfield/pull/130) fix: check status of object before mirroring
* [\#122](https://github.com/bnb-chain/greenfield/pull/122) chore: refine permission module for code quality
* [\#128](https://github.com/bnb-chain/greenfield/pull/128) docs: add the banner of gnfd
* [\#121](https://github.com/bnb-chain/greenfield/pull/121) chore: code quality self-review of ante handler
* [\#103](https://github.com/bnb-chain/greenfield/pull/103) feat: add challenger address to validators
* [\#123](https://github.com/bnb-chain/greenfield/pull/123) feat: add max buckets per account to params
* [\#110](https://github.com/bnb-chain/greenfield/pull/110) feat: add expiration and limit size for policy
* [\#118](https://github.com/bnb-chain/greenfield/pull/118) chore: refine the code of the storage mode


## v0.0.9
The resource mirror is introduced in this release.

Expand Down
8 changes: 6 additions & 2 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
return nil, errors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

if options.GashubKeeper == nil {
return nil, errors.Wrap(sdkerrors.ErrLogic, "gashub keeper is required for ante builder")
}

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
SingleMessageDecorator{}, // To support EIP712, only one msg is allowed
NewSignModeDecorator(options.SignModeHandler), // To support EIP712, only SignMode_SIGN_MODE_EIP_712 is allowed
SingleMessageDecorator{}, // Only one msg is allowed in EIP712 tx
NewSignModeDecorator(options.SignModeHandler), // Only SignMode_SIGN_MODE_EIP_712 is allowed
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
Expand Down
180 changes: 77 additions & 103 deletions app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,41 @@ package ante_test
import (
"encoding/hex"
"fmt"
"time"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/evmos/ethermint/crypto/ethsecp256k1"
"github.com/evmos/ethermint/tests"

"github.com/bnb-chain/greenfield/sdk/client/test"
)

func (suite *AnteTestSuite) TestAnteHandler() {
var acc authtypes.AccountI
addr, privKey := tests.NewAddrKey()
fmt.Println("Private Key:", hex.EncodeToString(privKey.Bytes()))
fmt.Println("Public Key:", hex.EncodeToString(privKey.PubKey().Bytes()))
fmt.Println("Address:", addr.String())
fmt.Printf("Sender Private Key: %x\n", privKey.Bytes())
fmt.Printf("Sender Public Key: %x\n", privKey.PubKey().Bytes())
fmt.Printf("Sender Address: %s\n", addr.String())

setup := func() {
suite.enableFeeMarket = false
suite.SetupTest() // reset
suite.SetupTest()

acc = suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr.Bytes())
suite.Require().NoError(acc.SetSequence(1))
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)

// get coins from validator
bz, _ := hex.DecodeString(genesisAccountPrivateKeyForTest)
senderPubKey := &ethsecp256k1.PubKey{Key: bz}
_ = suite.app.BankKeeper.SendCoins(suite.ctx, senderPubKey.Address().Bytes(), acc.GetAddress(), sdk.Coins{sdk.Coin{
bz, _ := hex.DecodeString(test.TEST_PUBKEY)
faucetPubKey := &ethsecp256k1.PubKey{Key: bz}
err := suite.app.BankKeeper.SendCoins(suite.ctx, faucetPubKey.Address().Bytes(), acc.GetAddress(), sdk.Coins{sdk.Coin{
Denom: sdk.DefaultBondDenom,
Amount: sdk.NewInt(100000000000000),
}})
if err != nil {
panic(err)
}
}

testCases := []struct {
Expand All @@ -48,167 +49,140 @@ func (suite *AnteTestSuite) TestAnteHandler() {
}{
// ensure all msg type could pass test
{
"success - DeliverTx EIP712 signed Cosmos Tx with MsgSend",
"success - DeliverTx EIP712 signed Cosmos Tx MsgSend",
func() sdk.Tx {
from := acc.GetAddress()
gas := uint64(2000000000)
amount := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100*int64(gas))))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "greenfield_9000-1", gas, amount)
gas := uint64(12e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "greenfield_9000-1", gas, fee)
return txBuilder.GetTx()
}, false, false, true,
}, true, false, true,
},
{
"success - DeliverTx EIP712 signed Cosmos Tx with MsgDelegate",
"success - DeliverTx EIP712 signed Cosmos Tx MsgDelegate",
func() sdk.Tx {
from := acc.GetAddress()
gas := uint64(2000000000)
coinAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100*int64(gas)))
amount := sdk.NewCoins(coinAmount)
txBuilder := suite.CreateTestEIP712TxBuilderMsgDelegate(from, privKey, "greenfield_9000-1", gas, amount)
gas := uint64(12e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgDelegate(from, privKey, "greenfield_9000-1", gas, fee)
return txBuilder.GetTx()
}, false, false, true,
}, true, false, true,
},
{
"success- DeliverTx EIP712 create validator",
"success - DeliverTx EIP712 signed Cosmos Tx MsgCreateValidator",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(2000000000)
txBuilder := suite.CreateTestEIP712MsgCreateValidator(from, privKey, "greenfield_9000-1", gas, amount)
gas := uint64(2e8)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712MsgCreateValidator(from, privKey, "greenfield_9000-1", gas, fee)
return txBuilder.GetTx()
}, false, false, true,
}, true, false, true,
},
{
"success- DeliverTx EIP712 MsgGrant",
"success - DeliverTx EIP712 signed Cosmos Tx MsgGrantAllowance",
func() sdk.Tx {
from := acc.GetAddress()
grantee := sdk.AccAddress("_______grantee______")
coinAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20))
gasAmount := sdk.NewCoins(coinAmount)
gas := uint64(2000000000)
blockTime := time.Date(1, 1, 1, 1, 1, 1, 1, time.UTC)
expiresAt := blockTime.Add(time.Hour)
msg, err := authz.NewMsgGrant(
from, grantee, &banktypes.SendAuthorization{SpendLimit: gasAmount}, &expiresAt,
)
suite.Require().NoError(err)
return suite.CreateTestEIP712CosmosTxBuilder(from, privKey, "greenfield_9000-1", gas, gasAmount, msg).GetTx()
}, false, false, true,
gas := uint64(16e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712GrantAllowance(from, privKey, "greenfield_9000-1", gas, fee)
return txBuilder.GetTx()
}, true, false, true,
},
{
"success- DeliverTx EIP712 MsgGrantAllowance",
"success - DeliverTx EIP712 signed Cosmos Tx MsgEditValidator",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20))
gasAmount := sdk.NewCoins(coinAmount)
gas := uint64(2000000000)
txBuilder := suite.CreateTestEIP712GrantAllowance(from, privKey, "greenfield_9000-1", gas, gasAmount)
gas := uint64(2e7)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712MsgEditValidator(from, privKey, "greenfield_9000-1", gas, fee)
return txBuilder.GetTx()
}, false, false, true,
}, true, false, true,
},
{
"success- DeliverTx EIP712 edit validator",
"success - DeliverTx EIP712 signed Cosmos Tx MsgSubmitProposalV1",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(2000000000)
txBuilder := suite.CreateTestEIP712MsgEditValidator(from, privKey, "greenfield_9000-1", gas, amount)
gas := uint64(2e8)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSubmitProposalV1(from, privKey, "greenfield_9000-1", gas, fee)
return txBuilder.GetTx()
}, false, false, true,
}, true, false, true,
},
{
"success- DeliverTx EIP712 submit evidence",
"success - DeliverTx EIP712 signed Cosmos Tx MsgGrant",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(2000000000)
txBuilder := suite.CreateTestEIP712MsgEditValidator(from, privKey, "greenfield_9000-1", gas, amount)
gas := uint64(16e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgGrant(from, privKey, "greenfield_9000-1", gas, fee)
return txBuilder.GetTx()
}, false, false, true,
}, true, false, true,
},
{
"success- DeliverTx EIP712 MsgSubmitProposalV1",
"fails - DeliverTx legacy msg MsgSubmitProposal v1beta",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(2000000000)
txBuilder := suite.CreateTestEIP712TxBuilderMsgSubmitProposalV1(from, privKey, "greenfield_9000-1", gas, amount)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
deposit := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(20)))
txBuilder := suite.CreateTestEIP712SubmitProposal(from, privKey, "greenfield_9000-1", gas, fee, deposit)
return txBuilder.GetTx()
}, false, false, true,
}, true, false, false,
},
{
"success- DeliverTx EIP712 MsgGrant",
"fails - DeliverTx unregistered msg type MsgSubmitEvidence",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(2000000000)
txBuilder := suite.CreateTestEIP712TxBuilderMsgGrant(from, privKey, "greenfield_9000-1", gas, amount)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712MsgSubmitEvidence(from, privKey, "greenfield_9000-1", gas, fee)
return txBuilder.GetTx()
}, false, false, true,
}, true, false, false,
},
// todo: fix this test after refactoring the gashub module
//{
// "fails- DeliverTx MsgSubmitProposal v1beta",
// func() sdk.Tx {
// from := acc.GetAddress()
// coinAmount := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20))
// gasAmount := sdk.NewCoins(coinAmount)
// gas := uint64(2000000000)
// // reusing the gasAmount for deposit
// deposit := sdk.NewCoins(coinAmount)
// txBuilder := suite.CreateTestEIP712SubmitProposal(from, privKey, "greenfield_9000-1", gas, gasAmount, deposit)
// return txBuilder.GetTx()
// }, false, false, false,
//},
{
"fails - DeliverTx EIP712 signed Cosmos Tx with wrong Chain ID",
func() sdk.Tx {
from := acc.GetAddress()
gas := uint64(2000000000)
amount := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100*int64(gas))))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "ethermint_9002-1", gas, amount)
gas := uint64(12e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "ethermint_9002-1", gas, fee)
return txBuilder.GetTx()
}, false, false, false,
}, true, false, false,
},
{
"fails - DeliverTx EIP712 signed Cosmos Tx with different gas fees",
func() sdk.Tx {
from := acc.GetAddress()
gas := uint64(2000000000)
amount := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100*int64(gas))))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "greenfield_9000-1", gas, amount)
gas := uint64(12e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "greenfield_9000-1", gas, fee)
txBuilder.SetGasLimit(uint64(300000))
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(30))))
return txBuilder.GetTx()
}, false, false, false,
}, true, false, false,
},
{
"fails - DeliverTx EIP712 signed Cosmos Tx with empty signature",
func() sdk.Tx {
from := acc.GetAddress()
gas := uint64(2000000000)
amount := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100*int64(gas))))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "greenfield_9000-1", gas, amount)
gas := uint64(12e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "greenfield_9000-1", gas, fee)
sigsV2 := signing.SignatureV2{
PubKey: privKey.PubKey(),
}
// nolint:errcheck
txBuilder.SetSignatures(sigsV2)
return txBuilder.GetTx()
}, false, false, false,
}, true, false, false,
},
{
"fails - DeliverTx EIP712 signed Cosmos Tx with invalid sequence",
func() sdk.Tx {
from := acc.GetAddress()
gas := uint64(2000000000)
amount := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100*int64(gas))))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "greenfield_9000-1", gas, amount)
gas := uint64(12e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "greenfield_9000-1", gas, fee)
nonce, err := suite.app.AccountKeeper.GetSequence(suite.ctx, acc.GetAddress())
suite.Require().NoError(err)
sigsV2 := signing.SignatureV2{
Expand All @@ -221,15 +195,15 @@ func (suite *AnteTestSuite) TestAnteHandler() {
// nolint:errcheck
txBuilder.SetSignatures(sigsV2)
return txBuilder.GetTx()
}, false, false, false,
}, true, false, false,
},
{
"fails - DeliverTx EIP712 signed Cosmos Tx with invalid signMode",
func() sdk.Tx {
from := acc.GetAddress()
gas := uint64(2000000000)
amount := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100*int64(gas))))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "greenfield_9000-1", gas, amount)
gas := uint64(12e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "greenfield_9000-1", gas, fee)
nonce, err := suite.app.AccountKeeper.GetSequence(suite.ctx, acc.GetAddress())
suite.Require().NoError(err)
sigsV2 := signing.SignatureV2{
Expand All @@ -242,7 +216,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
// nolint:errcheck
txBuilder.SetSignatures(sigsV2)
return txBuilder.GetTx()
}, false, false, false,
}, true, false, false,
},
}

Expand Down
Loading

0 comments on commit 72baa3a

Please sign in to comment.