-
Notifications
You must be signed in to change notification settings - Fork 126
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 #106 from renproject/feat/host_api
Added multichain api implementation for all evm compatible host chains
- Loading branch information
Showing
32 changed files
with
2,541 additions
and
46 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 avalanche | ||
|
||
import ( | ||
"github.com/renproject/multichain/chain/ethereum" | ||
) | ||
|
||
type ( | ||
// AddressEncodeDecoder re-exports ethereum.AddressEncodeDecoder. | ||
AddressEncodeDecoder = ethereum.AddressEncodeDecoder | ||
|
||
// AddressEncoder re-exports ethereum.AddressEncoder. | ||
AddressEncoder = ethereum.AddressEncoder | ||
|
||
// AddressDecoder re-exports ethereum.AddressDecoder. | ||
AddressDecoder = ethereum.AddressDecoder | ||
|
||
// Address re-exports ethereum.Address. | ||
Address = ethereum.Address | ||
) | ||
|
||
var ( | ||
// NewAddressEncodeDecoder re-exports ethereum.NewAddressEncodeDecoder. | ||
NewAddressEncodeDecoder = ethereum.NewAddressEncodeDecoder | ||
|
||
// NewAddressDecoder re-exports ethereum.NewAddressDecoder. | ||
NewAddressDecoder = ethereum.NewAddressDecoder | ||
|
||
// NewAddressEncoder re-exports ethereum.NewAddressEncoder. | ||
NewAddressEncoder = ethereum.NewAddressEncoder | ||
|
||
// NewAddressFromHex re-exports ethereum.NewAddressFromHex. | ||
NewAddressFromHex = ethereum.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,105 @@ | ||
package avalanche_test | ||
|
||
import ( | ||
"encoding/hex" | ||
"encoding/json" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/renproject/multichain/chain/avalanche" | ||
"github.com/renproject/surge" | ||
"testing/quick" | ||
) | ||
|
||
var _ = Describe("Address", func() { | ||
Context("when unmarshaling and unmarshaling", func() { | ||
It("should equal itself", func() { | ||
f := func(x [20]byte) bool { | ||
addr := avalanche.Address(x) | ||
Expect(addr.SizeHint()).To(Equal(20)) | ||
|
||
bytes, err := surge.ToBinary(addr) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
var newAddr avalanche.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 := avalanche.Address(x) | ||
|
||
bytes, err := json.Marshal(addr) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
var newAddr avalanche.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 avalanche.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 avalanche.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 avalanche.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 avalanche | ||
|
||
import ( | ||
"github.com/renproject/multichain/chain/ethereum" | ||
) | ||
|
||
const ( | ||
// DefaultClientRPCURL is the RPC URL used by default, to interact with the | ||
// avalanche node. | ||
DefaultClientRPCURL = "http://127.0.0.1:9650/ext/bc/C/rpc" | ||
) | ||
|
||
// Client re-exports ethereum.Client. | ||
type Client = ethereum.Client | ||
|
||
// NewClient re-exports ethereum.NewClient. | ||
var NewClient = ethereum.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 avalanche | ||
|
||
import ( | ||
"github.com/renproject/multichain/chain/ethereum" | ||
) | ||
|
||
// Payload re-exports ethereum.Payload. | ||
type Payload = ethereum.Payload | ||
|
||
// Encode re-exports ethereum.Encode. | ||
var Encode = ethereum.Encode |
Oops, something went wrong.