Skip to content

Commit

Permalink
remove gas price
Browse files Browse the repository at this point in the history
  • Loading branch information
ash-krishnan committed Jun 8, 2022
1 parent f8a1697 commit a28f476
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 98 deletions.
10 changes: 2 additions & 8 deletions services/construction/construction_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ var (
constructionToAddress = "0x3Fa177c2E87Cb24148EC403921dB577d140CC07c"

transferValue = uint64(20211004)
transferGasPrice = uint64(0)
transferGasLimit = uint64(21000)
transferGasLimitERC20 = uint64(65000)
transferNonce = uint64(67)
Expand All @@ -62,7 +61,6 @@ var (
transferGasTip = uint64(1000000000)

transferValueHex = hexutil.EncodeUint64(transferValue)
transferGasPriceHex = hexutil.EncodeUint64(transferGasPrice)
transferGasLimitHex = hexutil.EncodeUint64(transferGasLimit)
transferGasLimitERC20Hex = hexutil.EncodeUint64(transferGasLimitERC20)
transferNonceHex = hexutil.EncodeUint64(transferNonce)
Expand Down Expand Up @@ -160,7 +158,6 @@ func TestConstructionFlowWithPendingNonce(t *testing.T) {
// Test Metadata
metadata := &metadata{
GasLimit: 21000,
GasPrice: big.NewInt(0),
GasTip: big.NewInt(1500000000),
GasCap: big.NewInt(1501000000),
Nonce: 0,
Expand Down Expand Up @@ -209,7 +206,7 @@ func TestConstructionFlowWithPendingNonce(t *testing.T) {
}, metadataResponse)

// Test Payloads
unsignedRaw := `{"from":"0x5aCB42b3cfCD734a57AFF800139ba1354b549159","to":"0x3Fa177c2E87Cb24148EC403921dB577d140CC07c","value":"0x3e8","data":"0x","nonce":"0x0","gas_price":"0x0","max_fee_per_gas":"0x59777140","max_priority_fee_per_gas":"0x59682f00","gas":"0x5208","chain_id":"0x13881"}`
unsignedRaw := `{"from":"0x5aCB42b3cfCD734a57AFF800139ba1354b549159","to":"0x3Fa177c2E87Cb24148EC403921dB577d140CC07c","value":"0x3e8","data":"0x","nonce":"0x0","max_fee_per_gas":"0x59777140","max_priority_fee_per_gas":"0x59682f00","gas":"0x5208","chain_id":"0x13881"}`
payloadsResponse, err := servicer.ConstructionPayloads(ctx, &types.ConstructionPayloadsRequest{
NetworkIdentifier: networkIdentifier,
Operations: ops,
Expand All @@ -236,7 +233,6 @@ func TestConstructionFlowWithPendingNonce(t *testing.T) {
assert.Nil(t, err)
parseMetadata := &parseMetadata{
Nonce: metadata.Nonce,
GasPrice: metadata.GasPrice,
GasCap: metadata.GasCap,
GasTip: metadata.GasTip,
GasLimit: metadata.GasLimit,
Expand Down Expand Up @@ -373,7 +369,6 @@ func TestConstructionFlowWithInputNonce(t *testing.T) {
// Test Metadata
metadata := &metadata{
GasLimit: 21000,
GasPrice: big.NewInt(0),
GasTip: big.NewInt(1500000000),
GasCap: big.NewInt(1501000000),
Nonce: 1,
Expand Down Expand Up @@ -414,7 +409,7 @@ func TestConstructionFlowWithInputNonce(t *testing.T) {
}, metadataResponse)

// Test Payloads
unsignedRaw := `{"from":"0x5aCB42b3cfCD734a57AFF800139ba1354b549159","to":"0x3Fa177c2E87Cb24148EC403921dB577d140CC07c","value":"0x3e8","data":"0x","nonce":"0x1","gas_price":"0x0","max_fee_per_gas":"0x59777140","max_priority_fee_per_gas":"0x59682f00","gas":"0x5208","chain_id":"0x13881"}`
unsignedRaw := `{"from":"0x5aCB42b3cfCD734a57AFF800139ba1354b549159","to":"0x3Fa177c2E87Cb24148EC403921dB577d140CC07c","value":"0x3e8","data":"0x","nonce":"0x1","max_fee_per_gas":"0x59777140","max_priority_fee_per_gas":"0x59682f00","gas":"0x5208","chain_id":"0x13881"}`
payloadsResponse, err := servicer.ConstructionPayloads(ctx, &types.ConstructionPayloadsRequest{
NetworkIdentifier: networkIdentifier,
Operations: ops,
Expand All @@ -441,7 +436,6 @@ func TestConstructionFlowWithInputNonce(t *testing.T) {
assert.Nil(t, err)
parseMetadata := &parseMetadata{
Nonce: metadata.Nonce,
GasPrice: metadata.GasPrice,
GasLimit: metadata.GasLimit,
GasCap: metadata.GasCap,
GasTip: metadata.GasTip,
Expand Down
1 change: 0 additions & 1 deletion services/construction/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ func (a *APIService) ConstructionMetadata(

metadata := &metadata{
Nonce: nonce,
GasPrice: big.NewInt(0),
GasLimit: gasLimit,
GasCap: gasCap,
GasTip: gasTip,
Expand Down
27 changes: 0 additions & 27 deletions services/construction/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var (
maticTokenContract = "0x0000000000000000000000000000000000001010"
metadataMaticWithdrawData = "0x2e1a7d4d0000000000000000000000000000000000000000000000000000000005f5e100"

metadataGasPriceHex = "0x0"
)

func TestMetadata_Offline(t *testing.T) {
Expand Down Expand Up @@ -77,7 +76,6 @@ func TestMetadata(t *testing.T) {
"to": metadataTo,
"value": transferValueHex,
"nonce": transferNonceHex2,
"gas_price": metadataGasPriceHex,
"gas_limit": transferGasLimitHex,
"gas_cap": transferGasCapHex,
"gas_tip": transferGasTipHex,
Expand All @@ -98,10 +96,6 @@ func TestMetadata(t *testing.T) {
client.On("SuggestGasTipCap", ctx).
Return(big.NewInt(int64(transferGasTip)), nil)

// var gasPrice *big.Int = nil

// client.On("SuggestGasPrice", ctx, gasPrice).
// Return(big.NewInt(int64(transferGasPrice)), nil)
},
},
"happy path: native currency without nonce": {
Expand All @@ -123,17 +117,12 @@ func TestMetadata(t *testing.T) {
client.On("SuggestGasTipCap", ctx).
Return(big.NewInt(int64(transferGasTip)), nil)

// var gasPrice *big.Int = nil

//client.On("SuggestGasPrice", ctx, gasPrice).
// Return(big.NewInt(int64(transferGasTip)), nil)
},
expectedResponse: &types.ConstructionMetadataResponse{
Metadata: map[string]interface{}{
"to": metadataTo,
"value": transferValueHex,
"nonce": transferNonceHex,
"gas_price": metadataGasPriceHex,
"gas_limit": transferGasLimitHex,
"gas_cap": transferGasCapHex,
"gas_tip": transferGasTipHex,
Expand Down Expand Up @@ -173,17 +162,12 @@ func TestMetadata(t *testing.T) {
client.On("SuggestGasTipCap", ctx).
Return(big.NewInt(int64(transferGasTip)), nil)

// var gasPrice *big.Int = nil

// client.On("SuggestGasPrice", ctx, gasPrice).
// Return(big.NewInt(int64(transferGasPrice)), nil)
},
expectedResponse: &types.ConstructionMetadataResponse{
Metadata: map[string]interface{}{
"to": tokenContractAddress,
"value": "0x0",
"nonce": transferNonceHex2,
"gas_price": metadataGasPriceHex,
"gas_limit": transferGasLimitERC20Hex,
"gas_cap": transferGasCapHex,
"gas_tip": transferGasTipHex,
Expand Down Expand Up @@ -226,17 +210,12 @@ func TestMetadata(t *testing.T) {
client.On("SuggestGasTipCap", ctx).
Return(big.NewInt(int64(transferGasTip)), nil)

// var gasPrice *big.Int = nil

// client.On("SuggestGasPrice", ctx, gasPrice).
// Return(big.NewInt(int64(transferGasPrice)), nil)
},
expectedResponse: &types.ConstructionMetadataResponse{
Metadata: map[string]interface{}{
"to": tokenContractAddress,
"value": "0x0",
"nonce": transferNonceHex2,
"gas_price": metadataGasPriceHex,
"gas_limit": transferGasLimitERC20Hex,
"gas_cap": transferGasCapHex,
"gas_tip": transferGasTipHex,
Expand Down Expand Up @@ -274,11 +253,6 @@ func TestMetadata(t *testing.T) {
Value: big.NewInt(100000000),
}).Return(transferGasLimitERC20, nil)

// var gasPrice *big.Int = nil
//
// client.On("SuggestGasPrice", ctx, gasPrice).
// Return(big.NewInt(int64(transferGasPrice)), nil)

var blockNum *big.Int = nil

client.On("BlockHeader", ctx, blockNum).
Expand All @@ -292,7 +266,6 @@ func TestMetadata(t *testing.T) {
"to": maticTokenContract,
"value": "0x5f5e100",
"nonce": transferNonceHex2,
"gas_price": metadataGasPriceHex,
"gas_limit": transferGasLimitERC20Hex,
"gas_cap": transferGasCapHex,
"gas_tip": transferGasTipHex,
Expand Down
3 changes: 0 additions & 3 deletions services/construction/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"encoding/json"
"fmt"
"math/big"

"github.com/coinbase/rosetta-sdk-go/types"
ethTypes "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -49,7 +48,6 @@ func (a *APIService) ConstructionParse(
tx.Value = t.Value()
tx.Data = t.Data()
tx.Nonce = t.Nonce()
tx.GasPrice = big.NewInt(0)
tx.GasCap = t.GasFeeCap()
tx.GasTip = t.GasTipCap()
tx.GasLimit = t.Gas()
Expand Down Expand Up @@ -104,7 +102,6 @@ func (a *APIService) ConstructionParse(

metadata := &parseMetadata{
Nonce: tx.Nonce,
GasPrice: tx.GasPrice,
GasCap: tx.GasCap,
GasTip: tx.GasTip,
GasLimit: tx.GasLimit,
Expand Down
15 changes: 5 additions & 10 deletions services/construction/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,18 @@ import (
)

var (
unsignedMaticTransferTx = `{"from":"0x5aCB42b3cfCD734a57AFF800139ba1354b549159","to":"0x3Fa177c2E87Cb24148EC403921dB577d140CC07c","value":"0x3e8","data":"0x","nonce":"0x2","gas_price":"0x0","max_fee_per_gas":"0x59682f15","max_priority_fee_per_gas":"0x59682eff","gas":"0x5208","chain_id":"0x13881"}` //nolint:lll
unsignedMaticTransferTx = `{"from":"0x5aCB42b3cfCD734a57AFF800139ba1354b549159","to":"0x3Fa177c2E87Cb24148EC403921dB577d140CC07c","value":"0x3e8","data":"0x","nonce":"0x2","max_fee_per_gas":"0x59682f15","max_priority_fee_per_gas":"0x59682eff","gas":"0x5208","chain_id":"0x13881"}` //nolint:lll
signedMaticTransferTx = `{"type":"0x2","nonce":"0x2","gasPrice":null,"maxPriorityFeePerGas":"0x59682eff","maxFeePerGas":"0x59682f15","gas":"0x5208","value":"0x3e8","input":"0x","v":"0x1","r":"0x6afe2f65d311ff2430ca7388335b86e42606ea4728924d91564405df83d2cea5","s":"0x443a04f2d96ea9877ed67f2b45266446ab01de2154c268470f57bb12effa1563","to":"0x3fa177c2e87cb24148ec403921db577d140cc07c","chainId":"0x13881","accessList":[],"hash":"0x554c2edbd04b2be9d1314ef31201e3382eedb24a733f1b15448af2d16252db73"}` //nolint:lll
unsignedERC20TransferTx = `{"from":"0x5aCB42b3cfCD734a57AFF800139ba1354b549159","to":"0x2d7882beDcbfDDce29Ba99965dd3cdF7fcB10A1e","value":"0x0","data":"0xa9059cbb0000000000000000000000003fa177c2e87cb24148ec403921db577d140cc07c0000000000000000000000000000000000000000000000000000000000000064","nonce":"0x2","gas_price":"0x0","max_fee_per_gas":"0x9502f914","max_priority_fee_per_gas":"0x9502f900","gas":"0xb2cb","chain_id":"0x13881"}` //nolint:lll
unsignedERC20TransferTx = `{"from":"0x5aCB42b3cfCD734a57AFF800139ba1354b549159","to":"0x2d7882beDcbfDDce29Ba99965dd3cdF7fcB10A1e","value":"0x0","data":"0xa9059cbb0000000000000000000000003fa177c2e87cb24148ec403921db577d140cc07c0000000000000000000000000000000000000000000000000000000000000064","nonce":"0x2","max_fee_per_gas":"0x9502f914","max_priority_fee_per_gas":"0x9502f900","gas":"0xb2cb","chain_id":"0x13881"}` //nolint:lll
signedERC20TransferTx = `{"type":"0x2","nonce":"0x2","gasPrice":null,"maxPriorityFeePerGas":"0x9502f900","maxFeePerGas":"0x9502f914","gas":"0xb2cb","value":"0x0","input":"0xa9059cbb0000000000000000000000003fa177c2e87cb24148ec403921db577d140cc07c0000000000000000000000000000000000000000000000000000000000000064","v":"0x1","r":"0x2a8799b115741f62d5da931a53428ad1e3bf3055e9ea8427ce196a44cc590fca","s":"0x4779ab01b496c8b27e19efd24817557609b50da0d7e1a3790c435ca2225b43ae","to":"0x2d7882bedcbfddce29ba99965dd3cdf7fcb10a1e","chainId":"0x13881","accessList":[],"hash":"0xaa0f2056a79315e60a2012aee5f582692817e12153c6e45f57215f848893ec9e"}` //nolint:lll
unsignedERC20TransferTxInvalidData = `"{"from":"0x5aCB42b3cfCD734a57AFF800139ba1354b549159","to":"0x2d7882beDcbfDDce29Ba99965dd3cdF7fcB10A1e","value":"0x0","data":"0xaaaaaaaa000000000000000000000000efd3dc58d60af3295b92ecd484caeb3a2f30b3e7000000000000000000000000000000000000000000000000000000000134653c","nonce":"0x2","gas_price":"0x0","max_fee_per_gas":"0x9502f914","max_priority_fee_per_gas":"0x9502f900","gas":"0xb2cb","chain_id":"0x13881"}"` //nolint:lll
unsignedMaticTransferTxInvalidFrom = `{"from":"invalid_from","to":"0x3Fa177c2E87Cb24148EC403921dB577d140CC07c","value":"0x3e8","data":"0x","nonce":"0x2","gas_price":"0x0","max_fee_per_gas":"0x59682f15","max_priority_fee_per_gas":"0x59682eff","gas":"0x5208","chain_id":"0x13881"}` //nolint:lll
unsignedMaticTransferTxInvalidTo = `{"from":"0x5aCB42b3cfCD734a57AFF800139ba1354b549159","to":"invalid_to","value":"0x3e8","data":"0x","nonce":"0x2","gas_price":"0x0","max_fee_per_gas":"0x59682f15","max_priority_fee_per_gas":"0x59682eff","gas":"0x5208","chain_id":"0x13881"}` //nolint:lll
unsignedERC20TransferTxInvalidData = `"{"from":"0x5aCB42b3cfCD734a57AFF800139ba1354b549159","to":"0x2d7882beDcbfDDce29Ba99965dd3cdF7fcB10A1e","value":"0x0","data":"0xaaaaaaaa000000000000000000000000efd3dc58d60af3295b92ecd484caeb3a2f30b3e7000000000000000000000000000000000000000000000000000000000134653c","nonce":"0x2","max_fee_per_gas":"0x9502f914","max_priority_fee_per_gas":"0x9502f900","gas":"0xb2cb","chain_id":"0x13881"}"` //nolint:lll
unsignedMaticTransferTxInvalidFrom = `{"from":"invalid_from","to":"0x3Fa177c2E87Cb24148EC403921dB577d140CC07c","value":"0x3e8","data":"0x","nonce":"0x2","max_fee_per_gas":"0x59682f15","max_priority_fee_per_gas":"0x59682eff","gas":"0x5208","chain_id":"0x13881"}` //nolint:lll
unsignedMaticTransferTxInvalidTo = `{"from":"0x5aCB42b3cfCD734a57AFF800139ba1354b549159","to":"invalid_to","value":"0x3e8","data":"0x","nonce":"0x2","max_fee_per_gas":"0x59682f15","max_priority_fee_per_gas":"0x59682eff","gas":"0x5208","chain_id":"0x13881"}` //nolint:lll

parseFromAddress = "0x5aCB42b3cfCD734a57AFF800139ba1354b549159"
parseToAddress = "0x3Fa177c2E87Cb24148EC403921dB577d140CC07c"
parseTokenContractAddress = "0x2d7882beDcbfDDce29Ba99965dd3cdF7fcB10A1e"

gasPriceHex = "0x0"
gasCapHex = "0x59682f15"
gasTipHex = "0x59682eff"
nonceHex = "0x2"
Expand Down Expand Up @@ -70,7 +69,6 @@ func TestParse(t *testing.T) {
AccountIdentifierSigners: []*types.AccountIdentifier{},
Metadata: map[string]interface{}{
"nonce": nonceHex,
"gas_price": gasPriceHex,
"gas_limit": transferGasLimitHex,
"gas_cap": gasCapHex,
"gas_tip": gasTipHex,
Expand All @@ -93,7 +91,6 @@ func TestParse(t *testing.T) {
},
Metadata: map[string]interface{}{
"nonce": nonceHex,
"gas_price": gasPriceHex,
"gas_limit": transferGasLimitHex,
"gas_cap": gasCapHex,
"gas_tip": gasTipHex,
Expand All @@ -118,7 +115,6 @@ func TestParse(t *testing.T) {
AccountIdentifierSigners: []*types.AccountIdentifier{},
Metadata: map[string]interface{}{
"nonce": nonceERC20Hex,
"gas_price": gasPriceHex,
"gas_limit": gasLimitERC20Hex,
"gas_cap": gasCapERC20Hex,
"gas_tip": gasTipERC20Hex,
Expand Down Expand Up @@ -147,7 +143,6 @@ func TestParse(t *testing.T) {
},
Metadata: map[string]interface{}{
"nonce": nonceERC20Hex,
"gas_price": gasPriceHex,
"gas_limit": gasLimitERC20Hex,
"gas_cap": gasCapERC20Hex,
"gas_tip": gasTipERC20Hex,
Expand Down
2 changes: 0 additions & 2 deletions services/construction/payloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func (a *APIService) ConstructionPayloads(
amount := metadata.Value
toAdd := metadata.To
nonce := metadata.Nonce
gasPrice := metadata.GasPrice
gasCap := metadata.GasCap
gasTip := metadata.GasTip
chainID := a.config.Params.ChainID
Expand Down Expand Up @@ -95,7 +94,6 @@ func (a *APIService) ConstructionPayloads(
Value: amount,
Data: tx.Data(),
Nonce: tx.Nonce(),
GasPrice: gasPrice,
GasLimit: tx.Gas(),
GasCap: tx.GasFeeCap(),
GasTip: tx.GasTipCap(),
Expand Down
Loading

0 comments on commit a28f476

Please sign in to comment.