erigon-pulse/cmd/rpcdaemon/commands/starknet_send_transaction_test.go
ledgerwatch 8e3ac8a21c
Erigon2 upgrade 2 prototype (#4341)
* Erigon2 upgrade 2 prototype

* Latest erigon-lib

* Fixes

* Fix print

* Fix maxSpan

* Reduce maxSpan

* Remove duplicate joins

* TxNum

* Fix resuming

* first draft of history22

* Introduce historical reads

* Update to erigon-lib

* Update erigon-lib

* Update erigon-lib

* Fixes and tracing for checkChangeSets

* More trace

* Print account details

* fix getHeader

* Update to erigon-lib main

* Add tracer indices and event log indices

* Fix calltracer

* Fix calltracer

* Duplicate rpcdaemon into rpcdaemon22

* Fix tests

* Fix tests

* Fix tests

* Update to latest erigon-lib

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-06-10 16:18:43 +01:00

84 lines
2.4 KiB
Go

package commands_test
import (
"bytes"
"testing"
"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon-lib/gointerfaces/starknet"
"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"
"github.com/ledgerwatch/erigon/turbo/rpchelper"
"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)
starknetClient := starknet.NewCAIROVMClient(conn)
ff := rpchelper.New(ctx, nil, txPool, txpool.NewMiningClient(conn), func() {})
stateCache := kvcache.New(kvcache.DefaultCoherentConfig)
for _, tt := range cases {
api := commands.NewStarknetAPI(commands.NewBaseApi(ff, stateCache, snapshotsync.NewBlockReader(), false), m.DB, starknetClient, txPool)
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())
}