Skip to content

Commit

Permalink
types/ethtypes: add tests for calculating addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
susruth committed Sep 13, 2019
1 parent f840f8a commit 477943a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions types/ethtypes/address_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ethtypes_test

import (
"crypto/rand"
"encoding/hex"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/renproject/mercury/testutil"
"github.com/renproject/mercury/types/ethtypes"
)

var _ = Describe("eth addresses", func() {

Context("when calculating addresses", func() {
It("should calcualte an address from ecdsa public key correctly", func() {
key, err := testutil.RandomKey()
Expect(err).Should(BeNil())
Expect(func() { ethtypes.AddressFromPublicKey(&key.PublicKey) }).ShouldNot(Panic())
})

It("should calcualte an address from hex string correctly", func() {
addrBytes := [20]byte{}
rand.Read(addrBytes[:])
Expect(func() { ethtypes.AddressFromHex(hex.EncodeToString(addrBytes[:])) }).ShouldNot(Panic())
})
})

})

0 comments on commit 477943a

Please sign in to comment.