-
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 #109 from renproject/feat/arbitrum
Added multichain apis for Arbitrum
- Loading branch information
Showing
9 changed files
with
474 additions
and
16 deletions.
There are no files selected for viewing
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 arbitrum | ||
|
||
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 arbitrum_test | ||
|
||
import ( | ||
"encoding/hex" | ||
"encoding/json" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/renproject/multichain/chain/arbitrum" | ||
"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 := arbitrum.Address(x) | ||
Expect(addr.SizeHint()).To(Equal(20)) | ||
|
||
bytes, err := surge.ToBinary(addr) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
var newAddr arbitrum.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 := arbitrum.Address(x) | ||
|
||
bytes, err := json.Marshal(addr) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
var newAddr arbitrum.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 arbitrum.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 arbitrum.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 arbitrum.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 arbitrum | ||
|
||
import ( | ||
"github.com/renproject/multichain/chain/ethereum" | ||
) | ||
|
||
const ( | ||
// DefaultClientRPCURL is the RPC URL used by default, to interact with the | ||
// arbitrum node. | ||
DefaultClientRPCURL = "http://127.0.0.1:8547" | ||
) | ||
|
||
// 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 arbitrum | ||
|
||
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.