Skip to content

Commit

Permalink
Merge pull request #143 from renproject/feat/evm-support
Browse files Browse the repository at this point in the history
Support for Moonbeam and Kava
  • Loading branch information
jazg authored Apr 14, 2022
2 parents 5161f01 + 47f0fca commit 60047d1
Show file tree
Hide file tree
Showing 17 changed files with 914 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @loongy @jazg
@jazg @tok-kkk
33 changes: 33 additions & 0 deletions chain/kava/address.go
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
)
107 changes: 107 additions & 0 deletions chain/kava/address_test.go
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())
})
})
})
17 changes: 17 additions & 0 deletions chain/kava/client.go
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
11 changes: 11 additions & 0 deletions chain/kava/encode.go
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
Loading

0 comments on commit 60047d1

Please sign in to comment.