Skip to content

Commit

Permalink
Merge pull request #109 from renproject/feat/arbitrum
Browse files Browse the repository at this point in the history
Added multichain apis for Arbitrum
  • Loading branch information
roynalnaruto authored Jul 1, 2021
2 parents 46fd194 + 44d7a5c commit 9b656bf
Show file tree
Hide file tree
Showing 9 changed files with 474 additions and 16 deletions.
33 changes: 33 additions & 0 deletions chain/arbitrum/address.go
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
)
105 changes: 105 additions & 0 deletions chain/arbitrum/address_test.go
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())
})
})
})
17 changes: 17 additions & 0 deletions chain/arbitrum/client.go
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
11 changes: 11 additions & 0 deletions chain/arbitrum/encode.go
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
Loading

0 comments on commit 9b656bf

Please sign in to comment.