2020-09-09 13:53:14 +00:00
|
|
|
package types_test
|
2019-12-13 19:50:19 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-06-29 17:02:21 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2022-01-03 16:18:13 +00:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2020-09-09 13:53:14 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
2020-07-02 15:19:48 +00:00
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
2020-09-08 15:58:19 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2021-04-17 10:00:07 +00:00
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
2020-09-08 15:58:19 +00:00
|
|
|
|
2022-09-07 06:36:11 +00:00
|
|
|
cryptocodec "github.com/cerc-io/laconicd/crypto/codec"
|
|
|
|
"github.com/cerc-io/laconicd/crypto/ethsecp256k1"
|
|
|
|
ethermintcodec "github.com/cerc-io/laconicd/encoding/codec"
|
|
|
|
"github.com/cerc-io/laconicd/types"
|
2019-12-13 19:50:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-04-17 10:00:07 +00:00
|
|
|
amino := codec.NewLegacyAmino()
|
|
|
|
cryptocodec.RegisterCrypto(amino)
|
2019-12-13 19:50:19 +00:00
|
|
|
}
|
|
|
|
|
2020-09-09 13:53:14 +00:00
|
|
|
type AccountTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
account *types.EthAccount
|
2021-06-29 17:02:21 +00:00
|
|
|
cdc codec.JSONCodec
|
2020-09-09 13:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *AccountTestSuite) SetupTest() {
|
2021-04-17 10:00:07 +00:00
|
|
|
privKey, err := ethsecp256k1.GenerateKey()
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
pubKey := privKey.PubKey()
|
|
|
|
addr := sdk.AccAddress(pubKey.Address())
|
|
|
|
baseAcc := authtypes.NewBaseAccount(addr, pubKey, 10, 50)
|
2020-09-09 13:53:14 +00:00
|
|
|
suite.account = &types.EthAccount{
|
|
|
|
BaseAccount: baseAcc,
|
2021-06-29 17:02:21 +00:00
|
|
|
CodeHash: common.Hash{}.String(),
|
2020-09-09 13:53:14 +00:00
|
|
|
}
|
2021-04-17 10:00:07 +00:00
|
|
|
|
|
|
|
interfaceRegistry := codectypes.NewInterfaceRegistry()
|
|
|
|
ethermintcodec.RegisterInterfaces(interfaceRegistry)
|
|
|
|
suite.cdc = codec.NewProtoCodec(interfaceRegistry)
|
2020-09-09 13:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccountTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(AccountTestSuite))
|
|
|
|
}
|
2022-01-03 16:18:13 +00:00
|
|
|
|
|
|
|
func (suite *AccountTestSuite) TestAccountType() {
|
2022-10-10 10:38:33 +00:00
|
|
|
suite.account.CodeHash = common.BytesToHash(crypto.Keccak256(nil)).Hex()
|
2022-01-03 16:18:13 +00:00
|
|
|
suite.Require().Equal(types.AccountTypeEOA, suite.account.Type())
|
2022-10-10 10:38:33 +00:00
|
|
|
suite.account.CodeHash = common.BytesToHash(crypto.Keccak256([]byte{1, 2, 3})).Hex()
|
2022-01-03 16:18:13 +00:00
|
|
|
suite.Require().Equal(types.AccountTypeContract, suite.account.Type())
|
|
|
|
}
|