2023-07-08 19:01:26 +02:00
|
|
|
package jsonrpc
|
2023-01-26 11:36:06 +07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcdaemontest"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetContractCreator(t *testing.T) {
|
|
|
|
m, _, _ := rpcdaemontest.CreateTestSentry(t)
|
2023-07-27 22:29:17 -03:00
|
|
|
api := NewOtterscanAPI(newBaseApiForTest(m), m.DB, 25)
|
2023-01-26 11:36:06 +07:00
|
|
|
|
|
|
|
addr := libcommon.HexToAddress("0x537e697c7ab75a26f9ecf0ce810e3154dfcaaf44")
|
|
|
|
expectCreator := libcommon.HexToAddress("0x71562b71999873db5b286df957af199ec94617f7")
|
|
|
|
expectCredByTx := libcommon.HexToHash("0x6e25f89e24254ba3eb460291393a4715fd3c33d805334cbd05c1b2efe1080f18")
|
2023-06-05 12:36:24 +07:00
|
|
|
t.Run("valid inputs", func(t *testing.T) {
|
2023-01-27 11:34:04 +07:00
|
|
|
require := require.New(t)
|
2023-01-26 11:36:06 +07:00
|
|
|
results, err := api.GetContractCreator(m.Ctx, addr)
|
|
|
|
require.NoError(err)
|
|
|
|
require.Equal(expectCreator, results.Creator)
|
|
|
|
require.Equal(expectCredByTx, results.Tx)
|
|
|
|
})
|
|
|
|
t.Run("not existing addr", func(t *testing.T) {
|
2023-01-27 11:34:04 +07:00
|
|
|
require := require.New(t)
|
2023-01-26 11:36:06 +07:00
|
|
|
results, err := api.GetContractCreator(m.Ctx, libcommon.HexToAddress("0x1234"))
|
|
|
|
require.NoError(err)
|
|
|
|
require.Nil(results)
|
|
|
|
})
|
|
|
|
t.Run("pass creator as addr", func(t *testing.T) {
|
2023-01-27 11:34:04 +07:00
|
|
|
require := require.New(t)
|
2023-01-26 11:36:06 +07:00
|
|
|
results, err := api.GetContractCreator(m.Ctx, expectCreator)
|
|
|
|
require.NoError(err)
|
|
|
|
require.Nil(results)
|
|
|
|
})
|
|
|
|
}
|