From 61479754d935e36993f7144d70d7c518cdb26a36 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Wed, 25 Nov 2020 11:20:36 -0500 Subject: Add avax API client and upgrade to avalanchego v1.0.5-client --- plugin/evm/vm_test.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'plugin/evm/vm_test.go') diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index 020b663..1b894ce 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -36,7 +36,7 @@ var ( ) func init() { - cb58 := formatting.CB58{} + var b []byte factory := crypto.FactorySECP256K1R{} for _, key := range []string{ @@ -44,8 +44,8 @@ func init() { "2MMvUMsxx6zsHSNXJdFD8yc5XkancvwyKPwpw4xUK3TCGDuNBY", "cxb7KpGWhDMALTjNNSJ7UQkkomPesyWAPUaWRGdyeBNzR6f35", } { - _ = cb58.FromString(key) - pk, _ := factory.ToPrivateKey(cb58.Bytes) + b, _ = formatting.Decode(formatting.CB58, key) + pk, _ := factory.ToPrivateKey(b) secpKey := pk.(*crypto.PrivateKeySECP256K1R) testKeys = append(testKeys, secpKey) testEthAddrs = append(testEthAddrs, GetEthAddress(secpKey)) @@ -63,11 +63,11 @@ func BuildGenesisTest(t *testing.T) []byte { if err := json.Unmarshal([]byte(genesisJSON), genesis); err != nil { t.Fatalf("Problem unmarshaling genesis JSON: %s", err) } - genesisReply, err := ss.BuildGenesis(nil, genesis) + genesisBytes, err := ss.BuildGenesis(nil, genesis) if err != nil { t.Fatalf("Failed to create test genesis") } - return genesisReply.Bytes + return genesisBytes } func NewContext() *snow.Context { @@ -102,7 +102,10 @@ func GenesisVM(t *testing.T, finishBootstrapping bool) (chan engCommon.Message, // The caller of this function is responsible for unlocking. ctx.Lock.Lock() - userKeystore := keystore.CreateTestKeystore() + userKeystore, err := keystore.CreateTestKeystore() + if err != nil { + t.Fatal(err) + } if err := userKeystore.AddUser(username, password); err != nil { t.Fatal(err) } @@ -112,7 +115,7 @@ func GenesisVM(t *testing.T, finishBootstrapping bool) (chan engCommon.Message, vm := &VM{ txFee: testTxFee, } - err := vm.Initialize( + err = vm.Initialize( ctx, prefixdb.New([]byte{1}, baseDB), genesisBytes, -- cgit v1.2.3-70-g09d2 From 627bc7f7fd75d385e623c3c5177c5aeb639a0e52 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Sun, 29 Nov 2020 14:38:44 -0500 Subject: Address comments --- coreth.go | 5 +---- plugin/evm/static_service.go | 21 +++++++++++++++++++-- plugin/evm/vm.go | 2 +- plugin/evm/vm_test.go | 6 +++++- 4 files changed, 26 insertions(+), 8 deletions(-) (limited to 'plugin/evm/vm_test.go') diff --git a/coreth.go b/coreth.go index 01bc9af..351a14d 100644 --- a/coreth.go +++ b/coreth.go @@ -2,7 +2,6 @@ package coreth import ( "crypto/ecdsa" - //"fmt" "io" "os" @@ -18,10 +17,8 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" - "github.com/ethereum/go-ethereum/trie" - - //"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/trie" "github.com/mattn/go-isatty" ) diff --git a/plugin/evm/static_service.go b/plugin/evm/static_service.go index 1b45939..7b0fa8b 100644 --- a/plugin/evm/static_service.go +++ b/plugin/evm/static_service.go @@ -7,15 +7,32 @@ import ( "context" "encoding/json" + "github.com/ava-labs/avalanchego/utils/formatting" "github.com/ava-labs/coreth/core" ) // StaticService defines the static API services exposed by the evm type StaticService struct{} +// BuildGenesisReply is the reply from BuildGenesis +type BuildGenesisReply struct { + Bytes string `json:"bytes"` + Encoding formatting.Encoding `json:"encoding"` +} + // BuildGenesis returns the UTXOs such that at least one address in [args.Addresses] is // referenced in the UTXO. -func (*StaticService) BuildGenesis(_ context.Context, args *core.Genesis) ([]byte, error) { +func (*StaticService) BuildGenesis(_ context.Context, args *core.Genesis) (*BuildGenesisReply, error) { bytes, err := json.Marshal(args) - return bytes, err + if err != nil { + return nil, err + } + bytesStr, err := formatting.Encode(formatting.Hex, bytes) + if err != nil { + return nil, err + } + return &BuildGenesisReply{ + Bytes: bytesStr, + Encoding: formatting.Hex, + }, nil } diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index aaf7f10..58ab600 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -131,9 +131,9 @@ func init() { c.RegisterType(&secp256k1fx.Credential{}), c.RegisterType(&secp256k1fx.Input{}), c.RegisterType(&secp256k1fx.OutputOwners{}), + Codec.RegisterCodec(codecVersion, c), ) - errs.Add(Codec.RegisterCodec(0, c)) if errs.Errored() { panic(errs.Err) } diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index 1b894ce..2993b3b 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -63,10 +63,14 @@ func BuildGenesisTest(t *testing.T) []byte { if err := json.Unmarshal([]byte(genesisJSON), genesis); err != nil { t.Fatalf("Problem unmarshaling genesis JSON: %s", err) } - genesisBytes, err := ss.BuildGenesis(nil, genesis) + genesisReply, err := ss.BuildGenesis(nil, genesis) if err != nil { t.Fatalf("Failed to create test genesis") } + genesisBytes, err := formatting.Decode(genesisReply.Encoding, genesisReply.Bytes) + if err != nil { + t.Fatalf("Failed to decode genesis bytes: %w", err) + } return genesisBytes } -- cgit v1.2.3-70-g09d2 From 415b1eb564efc70cf7e673358286e19de8551fbf Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Sun, 29 Nov 2020 15:23:59 -0500 Subject: Fix test formatting directive --- plugin/evm/vm_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugin/evm/vm_test.go') diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index 2993b3b..0e9c102 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -69,7 +69,7 @@ func BuildGenesisTest(t *testing.T) []byte { } genesisBytes, err := formatting.Decode(genesisReply.Encoding, genesisReply.Bytes) if err != nil { - t.Fatalf("Failed to decode genesis bytes: %w", err) + t.Fatalf("Failed to decode genesis bytes: %s", err) } return genesisBytes } -- cgit v1.2.3-70-g09d2