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

fix: support accesslist type tx and handle rpc transaction #73

Merged
merged 10 commits into from
Oct 21, 2024
16 changes: 8 additions & 8 deletions app/ibc-hooks/ack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Test_onAckIcs20Packet_memo(t *testing.T) {
codeBz, err := hexutil.Decode(counter.CounterBin)
require.NoError(t, err)

_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil)
_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil, nil)
require.NoError(t, err)

abi, err := counter.CounterMetaData.GetAbi()
Expand Down Expand Up @@ -87,7 +87,7 @@ func Test_onAckIcs20Packet_memo(t *testing.T) {
// check the contract state
queryInputBz, err := abi.Pack("count")
require.NoError(t, err)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(0).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -102,7 +102,7 @@ func Test_onAckIcs20Packet_memo(t *testing.T) {
require.NoError(t, err)

// check the contract state; increased by 99 if ack is success
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(99).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -114,7 +114,7 @@ func Test_onAckIcs20Packet_memo(t *testing.T) {
require.NoError(t, err)

// check the contract state; increased by 1 if ack is failed
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(100).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand Down Expand Up @@ -157,7 +157,7 @@ func Test_onAckPacket_memo_ICS721(t *testing.T) {
codeBz, err := hexutil.Decode(counter.CounterBin)
require.NoError(t, err)

_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil)
_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil, nil)
require.NoError(t, err)

abi, err := counter.CounterMetaData.GetAbi()
Expand Down Expand Up @@ -197,7 +197,7 @@ func Test_onAckPacket_memo_ICS721(t *testing.T) {
// check the contract state
queryInputBz, err := abi.Pack("count")
require.NoError(t, err)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(0).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -212,7 +212,7 @@ func Test_onAckPacket_memo_ICS721(t *testing.T) {
require.NoError(t, err)

// check the contract state; increased by 99 if ack is success
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(99).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -224,7 +224,7 @@ func Test_onAckPacket_memo_ICS721(t *testing.T) {
require.NoError(t, err)

// check the contract state; increased by 1 if ack is failed
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(100).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand Down
18 changes: 9 additions & 9 deletions app/ibc-hooks/receive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func Test_onReceiveIcs20Packet_memo(t *testing.T) {
codeBz, err := hexutil.Decode(counter.CounterBin)
require.NoError(t, err)

_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil)
_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil, nil)
require.NoError(t, err)

abi, err := counter.CounterMetaData.GetAbi()
Expand Down Expand Up @@ -105,7 +105,7 @@ func Test_onReceiveIcs20Packet_memo(t *testing.T) {
require.NoError(t, err)

// check the contract state
queryRes, err := input.EVMKeeper.EVMStaticCall(ctx, evmAddr, contractAddr, queryInputBz)
queryRes, err := input.EVMKeeper.EVMStaticCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(1).Bytes32(), [32]byte(queryRes))

Expand All @@ -114,7 +114,7 @@ func Test_onReceiveIcs20Packet_memo(t *testing.T) {
require.NoError(t, err)
queryInputBz, err = input.EVMKeeper.ERC20Keeper().GetERC20ABI().Pack("allowance", common.BytesToAddress(intermediateSender.Bytes()), contractAddr)
require.NoError(t, err)
queryRes, err = input.EVMKeeper.EVMStaticCall(ctx, evmtypes.StdAddress, erc20Addr, queryInputBz)
queryRes, err = input.EVMKeeper.EVMStaticCall(ctx, evmtypes.StdAddress, erc20Addr, queryInputBz, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(10000).Bytes32(), [32]byte(queryRes))
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func Test_onReceivePacket_memo_ICS721(t *testing.T) {
codeBz, err := hexutil.Decode(counter.CounterBin)
require.NoError(t, err)

_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil)
_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil, nil)
require.NoError(t, err)

abi, err := counter.CounterMetaData.GetAbi()
Expand Down Expand Up @@ -222,7 +222,7 @@ func Test_onReceivePacket_memo_ICS721(t *testing.T) {
require.NoError(t, err)

// check the contract state
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(1).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -234,7 +234,7 @@ func Test_onReceivePacket_memo_ICS721(t *testing.T) {
require.NoError(t, err)
queryInputBz, err = input.EVMKeeper.ERC721Keeper().GetERC721ABI().Pack("getApproved", tokenId)
require.NoError(t, err)
queryRes, err = input.EVMKeeper.EVMStaticCall(ctx, evmtypes.StdAddress, erc721Addr, queryInputBz)
queryRes, err = input.EVMKeeper.EVMStaticCall(ctx, evmtypes.StdAddress, erc721Addr, queryInputBz, nil)
require.NoError(t, err)
require.Equal(t, contractAddr.Bytes(), common.HexToAddress(hexutil.Encode(queryRes)).Bytes())
}
Expand All @@ -248,7 +248,7 @@ func Test_onReceivePacket_memo_ICS721_Wasm(t *testing.T) {
codeBz, err := hexutil.Decode(counter.CounterBin)
require.NoError(t, err)

_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil)
_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil, nil)
require.NoError(t, err)

abi, err := counter.CounterMetaData.GetAbi()
Expand Down Expand Up @@ -316,7 +316,7 @@ func Test_onReceivePacket_memo_ICS721_Wasm(t *testing.T) {
require.NoError(t, err)

// check the contract state
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(1).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -328,7 +328,7 @@ func Test_onReceivePacket_memo_ICS721_Wasm(t *testing.T) {
require.NoError(t, err)
queryInputBz, err = input.EVMKeeper.ERC721Keeper().GetERC721ABI().Pack("getApproved", tokenId)
require.NoError(t, err)
queryRes, err = input.EVMKeeper.EVMStaticCall(ctx, evmtypes.StdAddress, erc721Addr, queryInputBz)
queryRes, err = input.EVMKeeper.EVMStaticCall(ctx, evmtypes.StdAddress, erc721Addr, queryInputBz, nil)
require.NoError(t, err)
require.Equal(t, contractAddr.Bytes(), common.HexToAddress(hexutil.Encode(queryRes)).Bytes())
}
12 changes: 6 additions & 6 deletions app/ibc-hooks/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Test_onTimeoutIcs20Packet_memo(t *testing.T) {
codeBz, err := hexutil.Decode(counter.CounterBin)
require.NoError(t, err)

_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil)
_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil, nil)
require.NoError(t, err)

abi, err := counter.CounterMetaData.GetAbi()
Expand Down Expand Up @@ -81,7 +81,7 @@ func Test_onTimeoutIcs20Packet_memo(t *testing.T) {
// check the contract state
queryInputBz, err := abi.Pack("count")
require.NoError(t, err)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(0).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -96,7 +96,7 @@ func Test_onTimeoutIcs20Packet_memo(t *testing.T) {
require.NoError(t, err)

// check the contract state; increased by 99
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(99).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand Down Expand Up @@ -136,7 +136,7 @@ func Test_onTimeoutPacket_memo_ICS721(t *testing.T) {
codeBz, err := hexutil.Decode(counter.CounterBin)
require.NoError(t, err)

_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil)
_, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, evmAddr, codeBz, nil, nil)
require.NoError(t, err)

abi, err := counter.CounterMetaData.GetAbi()
Expand Down Expand Up @@ -169,7 +169,7 @@ func Test_onTimeoutPacket_memo_ICS721(t *testing.T) {
// check the contract state
queryInputBz, err := abi.Pack("count")
require.NoError(t, err)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err := input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(0).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand All @@ -184,7 +184,7 @@ func Test_onTimeoutPacket_memo_ICS721(t *testing.T) {
require.NoError(t, err)

// check the contract state; increased by 99
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil)
queryRes, logs, err = input.EVMKeeper.EVMCall(ctx, evmAddr, contractAddr, queryInputBz, nil, nil)
require.NoError(t, err)
require.Equal(t, uint256.NewInt(99).Bytes32(), [32]byte(queryRes))
require.Empty(t, logs)
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/erc721_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (suite *KeeperTestSuite) CreateNftClass(
inputBz, err := nftKeeper.ABI.Pack("", name, name)
suite.Require().NoError(err)

_, contractAddr, _, err := evmKeeper.EVMCreate(ctx, createAccountAddr, append(nftKeeper.ERC721Bin, inputBz...), nil)
_, contractAddr, _, err := evmKeeper.EVMCreate(ctx, createAccountAddr, append(nftKeeper.ERC721Bin, inputBz...), nil, nil)
suite.Require().NoError(err)

classId, err := evmtypes.ClassIdFromCollectionAddress(endpoint.Chain.GetContext(), nftKeeper, contractAddr)
Expand Down Expand Up @@ -166,7 +166,7 @@ func (suite *KeeperTestSuite) MintNft(
contractAddr, err := evmtypes.ContractAddressFromClassId(ctx, nftKeeper, classId)
suite.Require().NoError(err)

_, _, err = nftKeeper.EVMCall(ctx, createAccountAddr, contractAddr, inputBz, nil)
_, _, err = nftKeeper.EVMCall(ctx, createAccountAddr, contractAddr, inputBz, nil, nil)
suite.Require().NoError(err)
}

Expand Down
79 changes: 65 additions & 14 deletions jsonrpc/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
from, _ := coretypes.Sender(signer, tx)
v, r, s := tx.RawSignatureValues()
al := tx.AccessList()
yparity := hexutil.Uint64(v.Sign())

result := &RPCTransaction{
Type: hexutil.Uint64(tx.Type()),
From: from,
Expand All @@ -58,27 +56,80 @@
S: (*hexutil.Big)(s),
ChainID: (*hexutil.Big)(chainID),
Accesses: &al,
YParity: &yparity,
}

if blockHash != (common.Hash{}) {
result.BlockHash = &blockHash
result.BlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(blockNumber))
result.TransactionIndex = (*hexutil.Uint64)(&index)
}

switch tx.Type() {
case coretypes.LegacyTxType: // Legacy type returns nil on yparity
default: // Dynamic and Access List type returns yParity
yParityValue := (v.Uint64())
result.YParity = (*hexutil.Uint64)(&yParityValue)
}

return result
}

func (rpcTx RPCTransaction) ToTransaction() *coretypes.Transaction {
return coretypes.NewTx(&coretypes.LegacyTx{
Nonce: uint64(rpcTx.Nonce),
GasPrice: rpcTx.GasPrice.ToInt(),
Gas: uint64(rpcTx.Gas),
To: rpcTx.To,
Value: rpcTx.Value.ToInt(),
Data: rpcTx.Input,
V: rpcTx.V.ToInt(),
R: rpcTx.R.ToInt(),
S: rpcTx.S.ToInt(),
})
gasPrice := func() *big.Int {
if rpcTx.GasPrice != nil {
return rpcTx.GasPrice.ToInt()
}
return big.NewInt(0)

Check warning on line 82 in jsonrpc/types/tx.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/types/tx.go#L82

Added line #L82 was not covered by tests
}()
accessList := func() coretypes.AccessList {
if rpcTx.Accesses != nil {
return *rpcTx.Accesses
}
return nil

Check warning on line 88 in jsonrpc/types/tx.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/types/tx.go#L88

Added line #L88 was not covered by tests
}()
switch rpcTx.Type {
case coretypes.LegacyTxType:
return coretypes.NewTx(&coretypes.LegacyTx{
Nonce: uint64(rpcTx.Nonce),
GasPrice: gasPrice,
Gas: uint64(rpcTx.Gas),
To: rpcTx.To,
Value: rpcTx.Value.ToInt(),
Data: rpcTx.Input,
V: rpcTx.V.ToInt(),
R: rpcTx.R.ToInt(),
S: rpcTx.S.ToInt(),
})
case coretypes.AccessListTxType:
return coretypes.NewTx(&coretypes.AccessListTx{
ChainID: rpcTx.ChainID.ToInt(),
Nonce: uint64(rpcTx.Nonce),
GasPrice: rpcTx.GasPrice.ToInt(),
Gas: uint64(rpcTx.Gas),
To: rpcTx.To,
Value: rpcTx.Value.ToInt(),
Data: rpcTx.Input,
AccessList: accessList,
V: rpcTx.V.ToInt(),
R: rpcTx.R.ToInt(),
S: rpcTx.S.ToInt(),
})
case coretypes.DynamicFeeTxType:
return coretypes.NewTx((&coretypes.DynamicFeeTx{
ChainID: rpcTx.ChainID.ToInt(),
Nonce: uint64(rpcTx.Nonce),
GasTipCap: rpcTx.GasTipCap.ToInt(),
GasFeeCap: rpcTx.GasFeeCap.ToInt(),
Gas: uint64(rpcTx.Gas),
To: rpcTx.To,
Value: rpcTx.Value.ToInt(),
Data: rpcTx.Input,
AccessList: accessList,
V: rpcTx.V.ToInt(),
R: rpcTx.R.ToInt(),
S: rpcTx.S.ToInt(),
}))
default:
return nil

Check warning on line 133 in jsonrpc/types/tx.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/types/tx.go#L132-L133

Added lines #L132 - L133 were not covered by tests
}
djm07073 marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading