Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement analyze methods send transaction accounts sign transaction send private transaction #166

Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
fb817db
eth_accounts method and the corresponding UT
novosandara Mar 26, 2024
0aa156e
Merge branch 'develop' into Implement-Analyze-Methods-sendTransaction…
novosandara Mar 26, 2024
dc6c98e
UT fix
novosandara Mar 27, 2024
75ececc
Merge branch 'develop' into Implement-Analyze-Methods-sendTransaction…
Stefan-Ethernal Mar 27, 2024
9d88475
Merge branch 'develop' into Implement-Analyze-Methods-sendTransaction…
novosandara Mar 27, 2024
c7d258b
eth_sendTransaction method and the corresponding tests (UT and e2e)
novosandara Mar 27, 2024
b94d134
eth_sendTransaction e2e fix
novosandara Mar 28, 2024
56aab5d
lint fix
novosandara Mar 28, 2024
99c1586
e2e fix
novosandara Mar 28, 2024
28367a3
eth_signTransaction method and the corresponding tests (UT and e2e)
novosandara Mar 28, 2024
bac326e
Merge branch 'develop' into Implement-Analyze-Methods-sendTransaction…
novosandara Mar 28, 2024
09984a1
e2e Test fix
novosandara Mar 30, 2024
efdd9f7
eth_signTransaction e2e fix
novosandara Mar 30, 2024
8cc0850
Merge branch 'develop' into Implement-Analyze-Methods-sendTransaction…
novosandara Mar 31, 2024
37f7791
e2e fix
novosandara Mar 31, 2024
b87af15
eth_signTransaction e2e fix
novosandara Mar 31, 2024
745a644
nonce too low, fix
novosandara Mar 31, 2024
dda1364
tidying up the code
novosandara Mar 31, 2024
28df87f
e2e test
novosandara Mar 31, 2024
6bff572
e2e fix
novosandara Mar 31, 2024
1478a40
e2e fix
novosandara Apr 1, 2024
f789b1b
Merge branch 'develop' into Implement-Analyze-Methods-sendTransaction…
novosandara Apr 1, 2024
d3b5859
Merge branch 'develop' into Implement-Analyze-Methods-sendTransaction…
novosandara Apr 8, 2024
00b2eb5
CR fix
novosandara Apr 8, 2024
4157d05
CR fix and method eth_sign
novosandara Apr 10, 2024
3a6c420
eth_sign, CR fix
novosandara Apr 14, 2024
08d9c7c
Merge branch 'develop' into Implement-Analyze-Methods-sendTransaction…
novosandara Apr 14, 2024
0a686bb
Merge branch 'develop' into Implement-Analyze-Methods-sendTransaction…
novosandara Apr 18, 2024
9ac3ba8
tidying up the code
novosandara Apr 19, 2024
02f138c
Merge branch 'develop' into Implement-Analyze-Methods-sendTransaction…
Stefan-Ethernal Apr 23, 2024
b0a5af1
reorgs
goran-ethernal Apr 23, 2024
0eb93b6
test and lint fix
goran-ethernal Apr 24, 2024
304e9b1
eth_getProof
novosandara Apr 24, 2024
8fc8913
Merge branch 'develop' into Implement-Analyze-Methods-sendTransaction…
novosandara Apr 24, 2024
0672025
fix GetProof
novosandara Apr 25, 2024
c6c7d9e
lint fix
novosandara Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ func TestBlockchainWriteBody(t *testing.T) {
newChain := func(
t *testing.T,
txFromByTxHash map[types.Hash]types.Address,
path string,
) *Blockchain {
t.Helper()

Expand Down Expand Up @@ -604,7 +603,7 @@ func TestBlockchainWriteBody(t *testing.T) {

txFromByTxHash := map[types.Hash]types.Address{}

chain := newChain(t, txFromByTxHash, "t1")
chain := newChain(t, txFromByTxHash)
defer chain.db.Close()
batchWriter := chain.db.NewWriter()

Expand Down Expand Up @@ -633,7 +632,7 @@ func TestBlockchainWriteBody(t *testing.T) {

txFromByTxHash := map[types.Hash]types.Address{}

chain := newChain(t, txFromByTxHash, "t2")
chain := newChain(t, txFromByTxHash)
defer chain.db.Close()
batchWriter := chain.db.NewWriter()

Expand Down Expand Up @@ -665,7 +664,7 @@ func TestBlockchainWriteBody(t *testing.T) {
tx.Hash(): addr,
}

chain := newChain(t, txFromByTxHash, "t3")
chain := newChain(t, txFromByTxHash)
defer chain.db.Close()
batchWriter := chain.db.NewWriter()

Expand Down
7 changes: 6 additions & 1 deletion consensus/polybft/wallet/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ func (a *Account) Save(secretsManager secrets.SecretsManager) (err error) {
}

func (a *Account) GetEcdsaPrivateKey() (*ecdsa.PrivateKey, error) {
ecdsaRaw, err := a.Ecdsa.MarshallPrivateKey()
return AdaptECDSAPrivKey(a.Ecdsa)
}

// AdaptECDSAPrivKey converts ecdsa private key from wallet.Key to ecdsa.PrivateKey instance
novosandara marked this conversation as resolved.
Show resolved Hide resolved
func AdaptECDSAPrivKey(ecdsaKey *crypto.ECDSAKey) (*ecdsa.PrivateKey, error) {
ecdsaRaw, err := ecdsaKey.MarshallPrivateKey()
if err != nil {
return nil, err
}
Expand Down
42 changes: 1 addition & 41 deletions consensus/polybft/wallet/account_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package wallet

import (
"fmt"
"testing"

"github.com/0xPolygon/polygon-edge/secrets"
Expand All @@ -12,7 +11,7 @@ import (
func TestAccount(t *testing.T) {
t.Parallel()

secretsManager := newSecretsManagerMock()
secretsManager := secrets.NewSecretsManagerMock()

key := generateTestAccount(t)
pubKeyMarshalled := key.Bls.PublicKey().Marshal()
Expand All @@ -33,10 +32,6 @@ func TestAccount(t *testing.T) {
assert.Equal(t, privKeyMarshalled, privKeyMarshalled1)
}

func newSecretsManagerMock() secrets.SecretsManager {
return &secretsManagerMock{cache: make(map[string][]byte)}
}

func generateTestAccount(t *testing.T) *Account {
t.Helper()

Expand All @@ -45,38 +40,3 @@ func generateTestAccount(t *testing.T) *Account {

return acc
}

type secretsManagerMock struct {
cache map[string][]byte
}

func (sm *secretsManagerMock) Setup() error {
return nil
}

func (sm *secretsManagerMock) GetSecret(name string) ([]byte, error) {
value, exists := sm.cache[name]
if !exists {
return nil, fmt.Errorf("secret does not exists for %s", name)
}

return value, nil
}

func (sm *secretsManagerMock) SetSecret(name string, value []byte) error {
sm.cache[name] = value

return nil
}

func (sm *secretsManagerMock) HasSecret(name string) bool {
_, exists := sm.cache[name]

return exists
}

func (sm *secretsManagerMock) RemoveSecret(name string) error {
delete(sm.cache, name)

return nil
}
64 changes: 64 additions & 0 deletions e2e-polybft/e2e/jsonrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,70 @@ func TestE2E_JsonRPC(t *testing.T) {
require.NotEqual(t, types.ZeroHash, hash)
})

t.Run("eth_sendTransaction", func(t *testing.T) {
deployTxn := cluster.Deploy(t, preminedAcct, contractsapi.TestSimple.Bytecode)
require.True(t, deployTxn.Succeed())

newNonce, err := newEthClient.GetNonce(preminedAcct.Address(), bladeRPC.LatestBlockNumberOrHash)
require.NoError(t, err)

target := types.Address(deployTxn.Receipt().ContractAddress)
input := contractsapi.TestSimple.Abi.GetMethod("getValue").ID()

gasPrice, err := newEthClient.GasPrice()
require.NoError(t, err)

txn := &bladeRPC.CallMsg{
From: types.ZeroAddress,
To: &target,
Gas: 92100,
GasPrice: new(big.Int).SetUint64(gasPrice),
Nonce: newNonce,
Data: input,
}

hash, err := newEthClient.SendTransactionCallMsg(txn)
require.NoError(t, err)
require.NotEqual(t, types.ZeroHash, hash)
})

t.Run("eth_signTransaction", func(t *testing.T) {
deployTxn := cluster.Deploy(t, preminedAcct, contractsapi.TestSimple.Bytecode)
require.True(t, deployTxn.Succeed())

target := types.Address(deployTxn.Receipt().ContractAddress)
input := contractsapi.TestSimple.Abi.GetMethod("getValue").ID()

zeroAddress := types.ZeroAddress

newNonce, err := newEthClient.GetNonce(target, bladeRPC.LatestBlockNumberOrHash)
require.NoError(t, err)

chainID, err := newEthClient.ChainID()
require.NoError(t, err)

gasPrice, err := newEthClient.GasPrice()
require.NoError(t, err)

txn := &bladeRPC.CallMsg{
From: zeroAddress,
To: &target,
Gas: 2100,
GasPrice: new(big.Int).SetUint64(gasPrice),
//MaxPriorityFeePerGas: new(big.Int).SetUint64(0),
//MaxFeePerGas: new(big.Int).SetUint64(10),
Nonce: newNonce,
Data: input,
ChainID: chainID,
}

res, err := newEthClient.SignTransaction(txn)
require.NoError(t, err)
require.NotEqual(t, types.ZeroHash, res.Tx.From)
require.NotNil(t, res.Raw)
require.NotEqual(t, 0, len(*res.Raw))
})

t.Run("eth_getHeaderByNumber", func(t *testing.T) {
key1, err := crypto.GenerateECDSAKey()
require.NoError(t, err)
Expand Down
7 changes: 5 additions & 2 deletions e2e-polybft/framework/test-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const (
NativeTokenMintableTestCfg = "Mintable Edge Coin:MEC:18" //nolint:gosec
)

var (
addressRegExp = regexp.MustCompile(`\(address\) = 0x([a-fA-F0-9]+)`)
)

type NodeType int

const (
Expand Down Expand Up @@ -987,8 +991,7 @@ func (c *TestCluster) InitSecrets(prefix string, count int) ([]types.Address, er
return nil, err
}

re := regexp.MustCompile(`\(address\) = 0x([a-fA-F0-9]+)`)
parsed := re.FindAllStringSubmatch(b.String(), -1)
parsed := addressRegExp.FindAllStringSubmatch(b.String(), -1)
result := make([]types.Address, len(parsed))

for i, v := range parsed {
Expand Down
9 changes: 9 additions & 0 deletions helper/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ func BigMin(x, y *big.Int) *big.Int {
return x
}

// BigMax returns the larger of x or y.
func BigMax(x, y *big.Int) *big.Int {
if x.Cmp(y) > 0 {
return x
}

return y
}

func ConvertUnmarshalledUint(x interface{}) (uint64, error) {
switch tx := x.(type) {
case float64:
Expand Down
1 change: 1 addition & 0 deletions jsonrpc/bridge_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestBridgeEndpoint(t *testing.T) {
priceLimit: 0,
jsonRPCBatchLengthLimit: 20,
blockRangeLimit: 1000,
secretsManager: setupSecretsManagerWithKey(t),
},
)

Expand Down
16 changes: 16 additions & 0 deletions jsonrpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ func (e *EthClient) SendTransaction(txn *types.Transaction) (types.Hash, error)
return hash, err
}

// SendTransaction creates new message call transaction or a contract creation
func (e *EthClient) SendTransactionCallMsg(msg *CallMsg) (types.Hash, error) {
var hash types.Hash
err := e.client.Call("eth_sendTransaction", &hash, msg)

return hash, err
}

// SendTransaction creates new message call transaction or a contract creation
func (e *EthClient) SignTransaction(msg *CallMsg) (*SignTransactionResult, error) {
var signTransactionResult *SignTransactionResult
err := e.client.Call("eth_signTransaction", &signTransactionResult, msg)

return signTransactionResult, err
}

// GetTransactionReceipt returns the receipt of a transaction by transaction hash
func (e *EthClient) GetTransactionReceipt(hash types.Hash) (*ethgo.Receipt, error) {
var receipt *ethgo.Receipt
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/debug_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (d *Debug) TraceCall(
return nil, ErrHeaderNotFound
}

tx, err := DecodeTxn(arg, header.Number, d.store, true)
tx, err := DecodeTxn(arg, d.store, true)
if err != nil {
return nil, err
}
Expand Down
22 changes: 11 additions & 11 deletions jsonrpc/debug_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,17 +593,17 @@ func TestTraceCall(t *testing.T) {
blockNumber = BlockNumber(testBlock10.Number())

txArg = &txnArgs{
From: &from,
To: &to,
Gas: &gas,
GasPrice: &gasPrice,
GasTipCap: &gasTipCap,
GasFeeCap: &gasFeeCap,
Value: &value,
Data: &data,
Input: &input,
Nonce: &nonce,
Type: toArgUint64Ptr(uint64(types.DynamicFeeTxType)),
From: &from,
To: &to,
Gas: &gas,
GasPrice: &gasPrice,
MaxPriorityFeePerGas: &gasTipCap,
MaxFeePerGas: &gasFeeCap,
Value: &value,
Data: &data,
Input: &input,
Nonce: &nonce,
Type: toArgUint64Ptr(uint64(types.DynamicFeeTxType)),
}
decodedTx = types.NewTx(types.NewDynamicFeeTx(
types.WithGasTipCap(new(big.Int).SetBytes([]byte(gasTipCap))),
Expand Down
20 changes: 15 additions & 5 deletions jsonrpc/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"time"
"unicode"

"github.com/0xPolygon/polygon-edge/crypto"
"github.com/0xPolygon/polygon-edge/secrets"
"github.com/armon/go-metrics"
"github.com/hashicorp/go-hclog"
jsonIter "github.com/json-iterator/go"
Expand Down Expand Up @@ -64,8 +66,10 @@ type dispatcherParams struct {
priceLimit uint64
jsonRPCBatchLengthLimit uint64
blockRangeLimit uint64

concurrentRequestsDebug uint64

secretsManager secrets.SecretsManager
txSigner crypto.TxSigner
}

func (dp dispatcherParams) isExceedingBatchLengthLimit(value uint64) bool {
Expand Down Expand Up @@ -95,13 +99,21 @@ func newDispatcher(
}

func (d *Dispatcher) registerEndpoints(store JSONRPCStore) error {
d.endpoints.Eth = &Eth{
var err error

d.endpoints.Eth, err = NewEth(
d.logger,
store,
d.params.chainID,
d.filterManager,
d.params.secretsManager,
d.params.chainID,
d.params.priceLimit,
d.params.txSigner,
)
if err != nil {
return err
}

d.endpoints.Net = &Net{
store,
d.params.chainID,
Expand All @@ -117,8 +129,6 @@ func (d *Dispatcher) registerEndpoints(store JSONRPCStore) error {
}
d.endpoints.Debug = NewDebug(store, d.params.concurrentRequestsDebug)

var err error

if err = d.registerService("eth", d.endpoints.Eth); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions jsonrpc/dispatcher_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func FuzzDispatcherFuncDecode(f *testing.F) {
priceLimit: 0,
jsonRPCBatchLengthLimit: 20,
blockRangeLimit: 1000,
secretsManager: setupSecretsManagerWithKey(f),
},
)

Expand Down Expand Up @@ -147,6 +148,7 @@ func FuzzDispatcherBatchRequest(f *testing.F) {
priceLimit: 0,
jsonRPCBatchLengthLimit: batchLimit,
blockRangeLimit: blockLimit,
secretsManager: setupSecretsManagerWithKey(t),
},
)

Expand All @@ -169,6 +171,7 @@ func FuzzDispatcherWebsocketConnectionUnsubscribe(f *testing.F) {
priceLimit: 0,
jsonRPCBatchLengthLimit: 20,
blockRangeLimit: 1000,
secretsManager: setupSecretsManagerWithKey(f),
},
)
mockConn := &mockWsConn{
Expand Down Expand Up @@ -207,6 +210,7 @@ func FuzzDispatcherWebSocketConnectionRequestFormats(f *testing.F) {
priceLimit: 0,
jsonRPCBatchLengthLimit: 20,
blockRangeLimit: 1000,
secretsManager: setupSecretsManagerWithKey(f),
},
)
mockConnection, _ := newMockWsConnWithMsgCh()
Expand Down
Loading
Loading