-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from renproject/feat/evm-support
Support for Moonbeam and Kava
- Loading branch information
Showing
17 changed files
with
914 additions
and
6 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
* @loongy @jazg | ||
@jazg @tok-kkk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package kava | ||
|
||
import ( | ||
"github.com/renproject/multichain/chain/evm" | ||
) | ||
|
||
type ( | ||
// AddressEncodeDecoder re-exports evm.AddressEncodeDecoder. | ||
AddressEncodeDecoder = evm.AddressEncodeDecoder | ||
|
||
// AddressEncoder re-exports evm.AddressEncoder. | ||
AddressEncoder = evm.AddressEncoder | ||
|
||
// AddressDecoder re-exports evm.AddressDecoder. | ||
AddressDecoder = evm.AddressDecoder | ||
|
||
// Address re-exports evm.Address. | ||
Address = evm.Address | ||
) | ||
|
||
var ( | ||
// NewAddressEncodeDecoder re-exports evm.NewAddressEncodeDecoder. | ||
NewAddressEncodeDecoder = evm.NewAddressEncodeDecoder | ||
|
||
// NewAddressDecoder re-exports evm.NewAddressDecoder. | ||
NewAddressDecoder = evm.NewAddressDecoder | ||
|
||
// NewAddressEncoder re-exports evm.NewAddressEncoder. | ||
NewAddressEncoder = evm.NewAddressEncoder | ||
|
||
// NewAddressFromHex re-exports evm.NewAddressFromHex. | ||
NewAddressFromHex = evm.NewAddressFromHex | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package kava_test | ||
|
||
import ( | ||
"encoding/hex" | ||
"encoding/json" | ||
"testing/quick" | ||
|
||
"github.com/renproject/multichain/chain/kava" | ||
"github.com/renproject/surge" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Address", func() { | ||
Context("when unmarshaling and unmarshaling", func() { | ||
It("should equal itself", func() { | ||
f := func(x [20]byte) bool { | ||
addr := kava.Address(x) | ||
Expect(addr.SizeHint()).To(Equal(20)) | ||
|
||
bytes, err := surge.ToBinary(addr) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
var newAddr kava.Address | ||
err = surge.FromBinary(&newAddr, bytes) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(addr).To(Equal(newAddr)) | ||
return true | ||
} | ||
|
||
err := quick.Check(f, nil) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
Context("when unmarshaling and unmarshaling to/from JSON", func() { | ||
It("should equal itself", func() { | ||
f := func(x [20]byte) bool { | ||
addr := kava.Address(x) | ||
|
||
bytes, err := json.Marshal(addr) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
var newAddr kava.Address | ||
err = json.Unmarshal(bytes, &newAddr) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(addr).To(Equal(newAddr)) | ||
return true | ||
} | ||
|
||
err := quick.Check(f, nil) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
Context("when the address is invalid hex", func() { | ||
It("should return an error", func() { | ||
f := func(x [40]byte) bool { | ||
bytes, err := json.Marshal(string(x[:])) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
var newAddr kava.Address | ||
err = json.Unmarshal(bytes, &newAddr) | ||
Expect(err).To(HaveOccurred()) | ||
return true | ||
} | ||
|
||
err := quick.Check(f, nil) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
Context("when the address is invalid length", func() { | ||
It("should return an error", func() { | ||
f := func(x [10]byte) bool { | ||
addr := hex.EncodeToString(x[:]) | ||
bytes, err := json.Marshal(addr) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
var newAddr kava.Address | ||
err = json.Unmarshal(bytes, &newAddr) | ||
Expect(err).To(HaveOccurred()) | ||
return true | ||
} | ||
|
||
err := quick.Check(f, nil) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
}) | ||
}) | ||
|
||
Context("when unmarshalling random data", func() { | ||
It("should not panic", func() { | ||
f := func(x []byte) bool { | ||
var addr kava.Address | ||
Expect(func() { addr.Unmarshal(x, surge.MaxBytes) }).ToNot(Panic()) | ||
Expect(func() { json.Unmarshal(x, &addr) }).ToNot(Panic()) | ||
return true | ||
} | ||
|
||
err := quick.Check(f, nil) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package kava | ||
|
||
import ( | ||
"github.com/renproject/multichain/chain/evm" | ||
) | ||
|
||
const ( | ||
// DefaultClientRPCURL is the RPC URL used by default, to interact with the | ||
// bsc node. | ||
DefaultClientRPCURL = "http://127.0.0.1:8575/" | ||
) | ||
|
||
// Client re-exports evm.Client. | ||
type Client = evm.Client | ||
|
||
// NewClient re-exports evm.NewClient. | ||
var NewClient = evm.NewClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package kava | ||
|
||
import ( | ||
"github.com/renproject/multichain/chain/evm" | ||
) | ||
|
||
// Payload re-exports evm.Payload. | ||
type Payload = evm.Payload | ||
|
||
// Encode re-exports evm.Encode. | ||
var Encode = evm.Encode |
Oops, something went wrong.