aboutsummaryrefslogtreecommitdiffstats
path: root/common/common_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'common/common_test.go')
-rw-r--r--common/common_test.go89
1 files changed, 89 insertions, 0 deletions
diff --git a/common/common_test.go b/common/common_test.go
new file mode 100644
index 000000000..c7ba87f90
--- /dev/null
+++ b/common/common_test.go
@@ -0,0 +1,89 @@
+package common
+
+import (
+ "bytes"
+ "math/big"
+ "os"
+ "testing"
+
+ checker "gopkg.in/check.v1"
+)
+
+type CommonSuite struct{}
+
+var _ = checker.Suite(&CommonSuite{})
+
+func (s *CommonSuite) TestOS(c *checker.C) {
+ expwin := (os.PathSeparator == '\\' && os.PathListSeparator == ';')
+ res := IsWindows()
+
+ if !expwin {
+ c.Assert(res, checker.Equals, expwin, checker.Commentf("IsWindows is", res, "but path is", os.PathSeparator))
+ } else {
+ c.Assert(res, checker.Not(checker.Equals), expwin, checker.Commentf("IsWindows is", res, "but path is", os.PathSeparator))
+ }
+}
+
+func (s *CommonSuite) TestWindonziePath(c *checker.C) {
+ iswindowspath := os.PathSeparator == '\\'
+ path := "/opt/eth/test/file.ext"
+ res := WindonizePath(path)
+ ressep := string(res[0])
+
+ if !iswindowspath {
+ c.Assert(ressep, checker.Equals, "/")
+ } else {
+ c.Assert(ressep, checker.Not(checker.Equals), "/")
+ }
+}
+
+func (s *CommonSuite) TestCommon(c *checker.C) {
+ douglas := CurrencyToString(BigPow(10, 43))
+ einstein := CurrencyToString(BigPow(10, 22))
+ ether := CurrencyToString(BigPow(10, 19))
+ finney := CurrencyToString(BigPow(10, 16))
+ szabo := CurrencyToString(BigPow(10, 13))
+ shannon := CurrencyToString(BigPow(10, 10))
+ babbage := CurrencyToString(BigPow(10, 7))
+ ada := CurrencyToString(BigPow(10, 4))
+ wei := CurrencyToString(big.NewInt(10))
+
+ c.Assert(douglas, checker.Equals, "10 Douglas")
+ c.Assert(einstein, checker.Equals, "10 Einstein")
+ c.Assert(ether, checker.Equals, "10 Ether")
+ c.Assert(finney, checker.Equals, "10 Finney")
+ c.Assert(szabo, checker.Equals, "10 Szabo")
+ c.Assert(shannon, checker.Equals, "10 Shannon")
+ c.Assert(babbage, checker.Equals, "10 Babbage")
+ c.Assert(ada, checker.Equals, "10 Ada")
+ c.Assert(wei, checker.Equals, "10 Wei")
+}
+
+func (s *CommonSuite) TestLarge(c *checker.C) {
+ douglaslarge := CurrencyToString(BigPow(100000000, 43))
+ adalarge := CurrencyToString(BigPow(100000000, 4))
+ weilarge := CurrencyToString(big.NewInt(100000000))
+
+ c.Assert(douglaslarge, checker.Equals, "10000E298 Douglas")
+ c.Assert(adalarge, checker.Equals, "10000E7 Einstein")
+ c.Assert(weilarge, checker.Equals, "100 Babbage")
+}
+
+//fromHex
+func TestFromHex(t *testing.T) {
+ input := "0x01"
+ expected := []byte{1}
+ result := FromHex(input)
+ if bytes.Compare(expected, result) != 0 {
+ t.Errorf("Expected % x got % x", expected, result)
+ }
+}
+
+func TestFromHexOddLength(t *testing.T) {
+ input := "0x1"
+ expected := []byte{1}
+ result := FromHex(input)
+ if bytes.Compare(expected, result) != 0 {
+ t.Errorf("Expected % x got % x", expected, result)
+ }
+}
1476ea474b933bf2f7b'>Add a patch to accomodate "const-poisoning" added into svn-1.7.mi2012-05-122-1/+20 * Unbreak -- it builds and starts-up here. If a library is missing in the listmi2012-05-071-9/+4 * Maintainer wishes to release this back into the wild.linimon2012-04-231-1/+1 * Mark as deprecated and set expiration to 2012-05-10 for ports that are mark a...bapt2012-04-101-0/+3 * - Get rid FreeBSD 6 supportmiwi2011-11-071-7/+1 * - Add LDFLAGS to CONFIGURE_ENV and MAKE_ENV (as it was done with LDFLAGS)amdmi32011-09-241-2/+2 * -remove MD5ohauer2011-07-031-1/+0 * - Mark BROKEN: does not linkpav2011-05-241-0/+2 * - Makes neon29 our default neon library. The neon 0.27.x to 0.29.x are API andmezz2010-07-311-2/+2 * - Chase devel/apr -> devel/apr1 shufflingpgollucci2010-05-181-1/+1 * 4/5: Chase devel/apr shlib bumppgollucci2010-05-061-1/+1 * - update to 1.4.1dinoex2010-03-281-1/+1 * - Switch to neon29pav2010-02-151-2/+2 * - Update to 2.0.0.b5p1amdmi32009-10-013-17/+7 * - Update to 2.0.0.b5pav2009-09-215-24/+71 * - Update boost to 1.39pav2009-07-281-1/+1 * - Fix build with subversion bumpdhn2009-04-082-1/+13 * o Remove devel/apr-svn and replace with devel/aprpgollucci2009-01-191-1/+1 * - Update to 2.0.0 beta 4miwi2008-08-267-22/+177 * Actually it's not broken, I had some stale packages on tindy (or maybe someoneitetcu2008-07-201-2/+0 * Mark broken since it depends on both neon28-0.28.2_1 and neon26-0.26.4_1 whichitetcu2008-07-201-0/+2 * - Update to 1.2.3miwi2008-07-184-51/+60 * - Bump PORTREVISION after apr updatemiwi2008-07-071-2/+2 * Bump portrevision due to upgrade of devel/gettext.edwin2008-06-061-0/+1 * Rename www/neon to www/neon26 to make the integrationedwin2008-05-051-1/+1 * - Remove unneeded dependency from gtk12/gtk20 [1]miwi2008-04-201-1/+1 * - Fix build: Subversion is needed for configure phase toopav2007-09-301-2/+2 * Fix build of devel/subcommanderedwin2007-09-101-2/+3