Skip to content

Commit

Permalink
TMP Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina committed Nov 13, 2023
1 parent de3431b commit 5a093d6
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 2 deletions.
13 changes: 11 additions & 2 deletions docker/kava-validator/kava-validator-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,26 @@ else
# ensure evm api listens on all addresses
sed -i 's/address = "127.0.0.1:8545"/address = "0.0.0.0:8545"/g' /root/.kava/config/app.toml

sed -in-place='' 's/stake/ukava/g' /root/.kava/config/genesis.json
sed -in-place='' 's/aphoton/akava/g' /root/.kava/config/genesis.json
sed -in-place='' 's/"max_gas": "-1"/"max_gas": "20000000"/' /root/.kava/config/genesis.json

# use the test backend to avoid prompts when storing and accessing keys
kava config keyring-backend test

# create an account for the delegator
# kava keys add kava-localnet-delegator
kava keys add kava-localnet-delegator

# add the delegator account to the default genesis
kava add-genesis-account $(kava keys show kava-localnet-delegator -a) 1000000000stake
kava add-genesis-account $(kava keys show kava-localnet-delegator -a) 1000000000ukava

# evm
echo 'canvas category slow immune screen van spirit ring blossom vanish mail pencil resource scan razor online gap void time marine topic swarm exhaust oak' | kava keys add evm --eth --recover
kava add-genesis-account $(kava keys show evm -a) 1000000000ukava

# create genesis info for a validator staked by the delegator above
kava gentx kava-localnet-delegator 500000000stake \
kava gentx kava-localnet-delegator 500000000ukava \
--chain-id=localnet_7777-1 \
--moniker="kava-localnet-validator"

Expand Down
158 changes: 158 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ package main_test
import (
"bytes"
"context"
"crypto/ecdsa"
"encoding/json"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"io"
"log"
"math/big"
"net/http"
"os"
Expand Down Expand Up @@ -1039,3 +1043,157 @@ func TestE2ETestCachingMdwForStaticMethods(t *testing.T) {

cleanUpRedis(t, redisClient)
}

func TestE2ETestCachingMdwForStaticMethods2(t *testing.T) {
// create api and database clients
client, err := ethclient.Dial(proxyServiceURL)
if err != nil {
t.Fatal(err)
}

// kava1vx6ah6qncne8nn7utm0nrk9vyzj7pntrqd0zfr
// BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
addr := common.HexToAddress("0x661C3ECC5bf3cdB64FC14c9fE9Fb64a21D24c51c")
balance, err := client.BalanceAt(context.Background(), addr, nil)
if err != nil {
log.Fatalf("can't get balance: %v\n", err)
}
fmt.Printf("%v\n", balance.String())

// PRIV_KEY=dabc9c936316cb11e5ded32d9bdc4125b990819d44c85acc246819124bda7447
{
privateKey, err := crypto.HexToECDSA("296da4e8defa5691077b310e10f0ed0ee4993e6418a0df86b155be5d24ae1b7c")
if err != nil {
log.Fatal(err)
}

publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey")
}

fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA)
fmt.Printf("FROM ADDR: %v\n", fromAddress)
nonce, err := client.PendingNonceAt(context.Background(), fromAddress)
if err != nil {
log.Fatal(err)
}

value := big.NewInt(1000000000000000000) // in wei (1 eth)
gasLimit := uint64(21000) // in units
gasPrice, err := client.SuggestGasPrice(context.Background())
if err != nil {
log.Fatal(err)
}

toAddress := common.HexToAddress("0x4592d8f8d7b001e72cb26a73e4fa1806a51ac79d")
var data []byte
tx := types.NewTransaction(nonce, toAddress, value, gasLimit, gasPrice, data)

chainID, err := client.NetworkID(context.Background())
if err != nil {
log.Fatal(err)
}

signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), privateKey)
if err != nil {
log.Fatal(err)
}

err = client.SendTransaction(context.Background(), signedTx)
if err != nil {
log.Fatalf("can't send tx: %v", err)
}

fmt.Printf("tx sent: %s", signedTx.Hash().Hex())
}

//redisClient := redis.NewClient(&redis.Options{
// Addr: redisURL,
// Password: redisPassword,
// DB: 0,
//})
//cleanUpRedis(t, redisClient)
//expectKeysNum(t, redisClient, 0)
//
//for _, tc := range []struct {
// desc string
// method string
// params []interface{}
// keysNum int
// expectedKey string
//}{
// {
// desc: "test case #1",
// method: "eth_chainId",
// params: []interface{}{},
// keysNum: 1,
// expectedKey: "local-chain:evm-request:eth_chainId:sha256:*",
// },
// {
// desc: "test case #2",
// method: "net_version",
// params: []interface{}{},
// keysNum: 2,
// expectedKey: "local-chain:evm-request:net_version:sha256:*",
// },
//} {
// t.Run(tc.desc, func(t *testing.T) {
// // test cache MISS and cache HIT scenarios for specified method
// // check corresponding values in cachemdw.CacheHeaderKey HTTP header
// // check that cached and non-cached responses are equal
//
// // cache MISS
// cacheMissResp := mkJsonRpcRequest(t, proxyServiceURL, 1, tc.method, tc.params)
// require.Equal(t, cachemdw.CacheMissHeaderValue, cacheMissResp.Header[cachemdw.CacheHeaderKey][0])
// body1, err := io.ReadAll(cacheMissResp.Body)
// require.NoError(t, err)
// err = checkJsonRpcErr(body1)
// require.NoError(t, err)
// expectKeysNum(t, redisClient, tc.keysNum)
// containsKey(t, redisClient, tc.expectedKey)
//
// // cache HIT
// cacheHitResp := mkJsonRpcRequest(t, proxyServiceURL, 1, tc.method, tc.params)
// require.Equal(t, cachemdw.CacheHitHeaderValue, cacheHitResp.Header[cachemdw.CacheHeaderKey][0])
// body2, err := io.ReadAll(cacheHitResp.Body)
// require.NoError(t, err)
// err = checkJsonRpcErr(body2)
// require.NoError(t, err)
// expectKeysNum(t, redisClient, tc.keysNum)
// containsKey(t, redisClient, tc.expectedKey)
//
// // check that response bodies are the same
// require.JSONEq(t, string(body1), string(body2), "blocks should be the same")
//
// // check that response headers are the same
// equalHeaders(t, cacheMissResp.Header, cacheHitResp.Header)
//
// // check that CORS headers are present for cache hit scenario
// require.Equal(t, cacheHitResp.Header[accessControlAllowOriginHeaderName], []string{"*"})
// })
//}
//
//cleanUpRedis(t, redisClient)
//// test cache MISS and cache HIT scenarios for eth_chainId method
//// check that cached and non-cached responses are equal
//{
// // eth_getBlockByNumber - cache MISS
// block1, err := client.ChainID(testContext)
// require.NoError(t, err)
// expectKeysNum(t, redisClient, 1)
// expectedKey := "local-chain:evm-request:eth_chainId:sha256:*"
// containsKey(t, redisClient, expectedKey)
//
// // eth_getBlockByNumber - cache HIT
// block2, err := client.ChainID(testContext)
// require.NoError(t, err)
// expectKeysNum(t, redisClient, 1)
// containsKey(t, redisClient, expectedKey)
//
// require.Equal(t, block1, block2, "blocks should be the same")
//}
//
//cleanUpRedis(t, redisClient)
}

0 comments on commit 5a093d6

Please sign in to comment.