2021-12-12 22:24:21 +00:00
|
|
|
package commands_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2022-03-18 08:06:23 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-12-12 22:24:21 +00:00
|
|
|
"github.com/holiman/uint256"
|
2022-01-20 15:34:00 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/gointerfaces/starknet"
|
2021-12-12 22:24:21 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/gointerfaces/txpool"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/kv/kvcache"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/commands"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcdaemontest"
|
|
|
|
"github.com/ledgerwatch/erigon/common"
|
|
|
|
"github.com/ledgerwatch/erigon/common/hexutil"
|
|
|
|
"github.com/ledgerwatch/erigon/core/types"
|
2022-06-10 15:18:43 +00:00
|
|
|
"github.com/ledgerwatch/erigon/turbo/rpchelper"
|
2021-12-12 22:24:21 +00:00
|
|
|
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
|
|
|
|
"github.com/ledgerwatch/erigon/turbo/stages"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestErrorStarknetSendRawTransaction(t *testing.T) {
|
|
|
|
var cases = []struct {
|
|
|
|
name string
|
|
|
|
tx string
|
|
|
|
error error
|
|
|
|
}{
|
|
|
|
{name: "wrong tx type", tx: generateDynamicFeeTransaction(), error: commands.ErrOnlyStarknetTx},
|
|
|
|
{name: "not contract creation", tx: generateStarknetTransaction(), error: commands.ErrOnlyContractDeploy},
|
|
|
|
}
|
|
|
|
|
|
|
|
m, require := stages.MockWithTxPool(t), require.New(t)
|
|
|
|
ctx, conn := rpcdaemontest.CreateTestGrpcConn(t, m)
|
|
|
|
txPool := txpool.NewTxpoolClient(conn)
|
2022-01-20 15:34:00 +00:00
|
|
|
starknetClient := starknet.NewCAIROVMClient(conn)
|
2022-06-10 15:18:43 +00:00
|
|
|
ff := rpchelper.New(ctx, nil, txPool, txpool.NewMiningClient(conn), func() {})
|
2021-12-12 22:24:21 +00:00
|
|
|
stateCache := kvcache.New(kvcache.DefaultCoherentConfig)
|
|
|
|
|
|
|
|
for _, tt := range cases {
|
2022-01-20 15:34:00 +00:00
|
|
|
api := commands.NewStarknetAPI(commands.NewBaseApi(ff, stateCache, snapshotsync.NewBlockReader(), false), m.DB, starknetClient, txPool)
|
2021-12-12 22:24:21 +00:00
|
|
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
hex, _ := hexutil.Decode(tt.tx)
|
|
|
|
|
|
|
|
_, err := api.SendRawTransaction(ctx, hex)
|
|
|
|
|
|
|
|
require.ErrorIs(err, tt.error)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateDynamicFeeTransaction() string {
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
types.DynamicFeeTransaction{
|
|
|
|
CommonTx: types.CommonTx{
|
|
|
|
ChainID: new(uint256.Int),
|
|
|
|
Nonce: 1,
|
|
|
|
Value: uint256.NewInt(1),
|
|
|
|
Gas: 1,
|
|
|
|
},
|
|
|
|
Tip: new(uint256.Int),
|
|
|
|
FeeCap: new(uint256.Int),
|
|
|
|
}.MarshalBinary(buf)
|
|
|
|
|
|
|
|
return hexutil.Encode(buf.Bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateStarknetTransaction() string {
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
types.StarknetTransaction{
|
|
|
|
CommonTx: types.CommonTx{
|
|
|
|
ChainID: new(uint256.Int),
|
|
|
|
Nonce: 1,
|
|
|
|
Value: uint256.NewInt(1),
|
|
|
|
Gas: 1,
|
|
|
|
To: &common.Address{},
|
|
|
|
},
|
|
|
|
Tip: new(uint256.Int),
|
|
|
|
FeeCap: new(uint256.Int),
|
|
|
|
}.MarshalBinary(buf)
|
|
|
|
|
|
|
|
return hexutil.Encode(buf.Bytes())
|
|
|
|
}
|