Skip to content

Commit

Permalink
chore: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Jun 20, 2024
1 parent b2e32e8 commit 8529915
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
5 changes: 2 additions & 3 deletions app/submodule/eth/eth_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/builtin"
builtintypes "github.com/filecoin-project/go-state-types/builtin"
"github.com/filecoin-project/go-state-types/builtin/v10/eam"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/exitcode"
Expand Down Expand Up @@ -549,12 +548,12 @@ func ethTxFromNativeMessage(ctx context.Context, msg *types.Message, ca v1.IChai
// Then we try to see if it's "special". If we fail, we ignore the error and keep treating
// it as a native message. Unfortunately, the user is free to send garbage that may not
// properly decode.
if msg.Method == builtintypes.MethodsEVM.InvokeContract {
if msg.Method == builtin.MethodsEVM.InvokeContract {
// try to decode it as a contract invocation first.
if inp, err := decodePayload(msg.Params, codec); err == nil {
ethTx.Input = []byte(inp)
}
} else if msg.To == builtin.EthereumAddressManagerActorAddr && msg.Method == builtintypes.MethodsEAM.CreateExternal {
} else if msg.To == builtin.EthereumAddressManagerActorAddr && msg.Method == builtin.MethodsEAM.CreateExternal {
// Then, try to decode it as a contract deployment from an EOA.
if inp, err := decodePayload(msg.Params, codec); err == nil {
ethTx.Input = []byte(inp)
Expand Down
8 changes: 4 additions & 4 deletions venus-shared/actors/types/eth_1559_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (tx *Eth1559TxArgs) InitialiseSignature(sig typescrypto.Signature) error {
}

func (tx *Eth1559TxArgs) packTxFields() ([]interface{}, error) {
chainId, err := formatInt(tx.ChainID)
chainID, err := formatInt(tx.ChainID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -202,7 +202,7 @@ func (tx *Eth1559TxArgs) packTxFields() ([]interface{}, error) {
}

res := []interface{}{
chainId,
chainID,
nonce,
maxPriorityFeePerGas,
maxFeePerGas,
Expand Down Expand Up @@ -233,7 +233,7 @@ func parseEip1559Tx(data []byte) (*Eth1559TxArgs, error) {
return nil, xerrors.Errorf("not an EIP-1559 transaction: should have 12 elements in the rlp list")
}

chainId, err := parseInt(decoded[0])
chainID, err := parseInt(decoded[0])
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -301,7 +301,7 @@ func parseEip1559Tx(data []byte) (*Eth1559TxArgs, error) {
}

args := Eth1559TxArgs{
ChainID: chainId,
ChainID: chainID,
Nonce: nonce,
To: to,
MaxPriorityFeePerGas: maxPriorityFeePerGas,
Expand Down
10 changes: 5 additions & 5 deletions venus-shared/actors/types/eth_legacy_155_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (tx *EthLegacy155TxArgs) ToRawTxBytesSigned() ([]byte, error) {
return nil, err
}

packed1 = packed1[:len(packed1)-3] // remove chainId, r and s as they are only used for signature verification
packed1 = packed1[:len(packed1)-3] // remove chainID, r and s as they are only used for signature verification

packed2, err := packSigFields(tx.legacyTx.V, tx.legacyTx.R, tx.legacyTx.S)
if err != nil {
Expand Down Expand Up @@ -239,7 +239,7 @@ func (tx *EthLegacy155TxArgs) packTxFields() ([]interface{}, error) {
}

chainIdBigInt := big.NewIntUnsigned(uint64(Eip155ChainID))

Check failure on line 241 in venus-shared/actors/types/eth_legacy_155_transactions.go

View workflow job for this annotation

GitHub Actions / check

ST1003: var chainIdBigInt should be chainIDBigInt (stylecheck)
chainId, err := formatBigInt(chainIdBigInt)
chainID, err := formatBigInt(chainIdBigInt)
if err != nil {
return nil, err
}
Expand All @@ -261,7 +261,7 @@ func (tx *EthLegacy155TxArgs) packTxFields() ([]interface{}, error) {
formatEthAddr(tx.legacyTx.To),
value,
tx.legacyTx.Input,
chainId,
chainID,
r, s,
}
return res, nil
Expand Down Expand Up @@ -290,8 +290,8 @@ func deriveEIP155ChainId(v big.Int) big.Int {
}

func calcEIP155TxSignatureLen(chain uint64, v int) int {
chainId := big.NewIntUnsigned(chain)
vVal := big.Add(big.Mul(chainId, big.NewInt(2)), big.NewInt(int64(v)))
chainID := big.NewIntUnsigned(chain)
vVal := big.Add(big.Mul(chainID, big.NewInt(2)), big.NewInt(int64(v)))
vLen := len(vVal.Int.Bytes())

// EthLegacyHomesteadTxSignatureLen includes the 1 byte legacy tx marker prefix and also 1 byte for the V value.
Expand Down
14 changes: 7 additions & 7 deletions venus-shared/actors/types/eth_legacy_155_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,39 +107,39 @@ func TestDeriveEIP155ChainId(t *testing.T) {
tests := []struct {
name string
v big.Int
expectedChainId big.Int
expectedChainID big.Int
}{
{
name: "V equals 27",
v: big.NewInt(27),
expectedChainId: big.NewInt(0),
expectedChainID: big.NewInt(0),
},
{
name: "V equals 28",
v: big.NewInt(28),
expectedChainId: big.NewInt(0),
expectedChainID: big.NewInt(0),
},
{
name: "V small chain ID",
v: big.NewInt(37), // (37 - 35) / 2 = 1
expectedChainId: big.NewInt(1),
expectedChainID: big.NewInt(1),
},
{
name: "V large chain ID",
v: big.NewInt(1001), // (1001 - 35) / 2 = 483
expectedChainId: big.NewInt(483),
expectedChainID: big.NewInt(483),
},
{
name: "V very large chain ID",
v: big.NewInt(1 << 20), // (1048576 - 35) / 2 = 524770
expectedChainId: big.NewInt(524270),
expectedChainID: big.NewInt(524270),
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := deriveEIP155ChainId(tt.v)
require.True(t, result.Equals(tt.expectedChainId), "Expected %s, got %s for V=%s", tt.expectedChainId.String(), result.String(), tt.v.String())
require.True(t, result.Equals(tt.expectedChainID), "Expected %s, got %s for V=%s", tt.expectedChainID.String(), result.String(), tt.v.String())
})
}
}
Expand Down

0 comments on commit 8529915

Please sign in to comment.