github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/evm/keeper/querier_test.go (about) 1 package keeper_test 2 3 import ( 4 "fmt" 5 ethcmn "github.com/ethereum/go-ethereum/common" 6 ethtypes "github.com/ethereum/go-ethereum/core/types" 7 abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types" 8 "github.com/fibonacci-chain/fbc/x/evm/types" 9 "math/big" 10 ) 11 12 func (suite *KeeperTestSuite) TestQuerier() { 13 14 testCases := []struct { 15 msg string 16 path []string 17 malleate func() 18 expPass bool 19 }{ 20 {"balance", []string{types.QueryBalance, addrHex}, func() { 21 suite.app.EvmKeeper.SetBalance(suite.ctx, suite.address, big.NewInt(5)) 22 }, true}, 23 //{"balance fail", []string{types.QueryBalance, "0x01232"}, func() {}, false}, 24 {"block number", []string{types.QueryBlockNumber}, func() {}, true}, 25 {"storage", []string{types.QueryStorage, "0x0", "0x0"}, func() {}, true}, 26 {"code", []string{types.QueryCode, "0x0"}, func() {}, true}, 27 {"hash to height", []string{types.QueryHashToHeight, hex}, func() { 28 suite.app.EvmKeeper.SetBlockHeight(suite.ctx, hash, 8) 29 }, true}, 30 {"fail hash to height", []string{types.QueryHashToHeight, "0x00"}, func() { 31 suite.app.EvmKeeper.SetBlockHeight(suite.ctx, hash, 8) 32 }, false}, 33 {"bloom", []string{types.QueryBloom, "4"}, func() { 34 testBloom := ethtypes.BytesToBloom([]byte{0x1, 0x3}) 35 suite.app.EvmKeeper.SetBlockBloom(suite.ctx, 4, testBloom) 36 }, true}, 37 {"fail bloom height", []string{types.QueryBloom, ""}, func() { 38 testBloom := ethtypes.BytesToBloom([]byte{0x1, 0x3}) 39 suite.app.EvmKeeper.SetBlockBloom(suite.ctx, 4, testBloom) 40 }, false}, 41 {"fail bloom number", []string{types.QueryBloom, "4"}, func() { 42 testBloom := ethtypes.BytesToBloom([]byte{0x1, 0x3}) 43 suite.app.EvmKeeper.SetBlockBloom(suite.ctx, 3, testBloom) 44 }, true}, 45 {"account", []string{types.QueryAccount, "0x0"}, func() {}, true}, 46 {"exportAccount", []string{types.QueryExportAccount, suite.address.String()}, func() { 47 for i := 0; i < 5; i++ { 48 suite.stateDB.WithContext(suite.ctx).SetState(suite.address, ethcmn.BytesToHash([]byte(fmt.Sprintf("key%d", i))), ethcmn.BytesToHash([]byte(fmt.Sprintf("value%d", i)))) 49 } 50 suite.stateDB.WithContext(suite.ctx).Finalise(false) 51 }, true}, 52 {"unknown request", []string{"other"}, func() {}, false}, 53 {"parameters", []string{types.QueryParameters}, func() {}, true}, 54 {"storage by key", []string{types.QueryStorageByKey, "0xE3Db5e3cfDbBa56FfdDED5792DaAB8A2DC9c52c4", "key"}, func() {}, true}, 55 {"storage height to hash", []string{types.QueryHeightToHash, "1"}, func() {}, true}, 56 //{"storage section", []string{types.QuerySection, "1"}, func() {}, true}, 57 {"contract deploy white list", []string{types.QueryContractDeploymentWhitelist}, func() {}, true}, 58 {"contract blocked list", []string{types.QueryContractBlockedList}, func() {}, true}, 59 {"contract method blocked list", []string{types.QueryContractMethodBlockedList}, func() {}, true}, 60 } 61 62 for i, tc := range testCases { 63 suite.Run("", func() { 64 //nolint 65 tc := tc 66 suite.SetupTest() // reset 67 //nolint 68 tc.malleate() 69 70 bz, err := suite.querier(suite.ctx, tc.path, abci.RequestQuery{}) 71 72 //nolint 73 if tc.expPass { 74 //nolint 75 suite.Require().NoError(err, "valid test %d failed: %s", i, tc.msg) 76 suite.Require().NotZero(len(bz)) 77 } else { 78 //nolint 79 suite.Require().Error(err, "invalid test %d passed: %s", i, tc.msg) 80 } 81 }) 82 } 83 }