common_test.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package ethutil
  2. import (
  3. "math/big"
  4. "os"
  5. checker "gopkg.in/check.v1"
  6. )
  7. type CommonSuite struct{}
  8. var _ = checker.Suite(&CommonSuite{})
  9. func (s *CommonSuite) TestOS(c *checker.C) {
  10. expwin := (os.PathSeparator == '\\' && os.PathListSeparator == ';')
  11. res := IsWindows()
  12. if !expwin {
  13. c.Assert(res, checker.Equals, expwin, checker.Commentf("IsWindows is", res, "but path is", os.PathSeparator))
  14. } else {
  15. c.Assert(res, checker.Not(checker.Equals), expwin, checker.Commentf("IsWindows is", res, "but path is", os.PathSeparator))
  16. }
  17. }
  18. func (s *CommonSuite) TestWindonziePath(c *checker.C) {
  19. iswindowspath := os.PathSeparator == '\\'
  20. path := "/opt/eth/test/file.ext"
  21. res := WindonizePath(path)
  22. ressep := string(res[0])
  23. if !iswindowspath {
  24. c.Assert(ressep, checker.Equals, "/")
  25. } else {
  26. c.Assert(ressep, checker.Not(checker.Equals), "/")
  27. }
  28. }
  29. func (s *CommonSuite) TestCommon(c *checker.C) {
  30. douglas := CurrencyToString(BigPow(10, 43))
  31. einstein := CurrencyToString(BigPow(10, 22))
  32. ether := CurrencyToString(BigPow(10, 19))
  33. finney := CurrencyToString(BigPow(10, 16))
  34. szabo := CurrencyToString(BigPow(10, 13))
  35. shannon := CurrencyToString(BigPow(10, 10))
  36. babbage := CurrencyToString(BigPow(10, 7))
  37. ada := CurrencyToString(BigPow(10, 4))
  38. wei := CurrencyToString(big.NewInt(10))
  39. c.Assert(douglas, checker.Equals, "10 Douglas")
  40. c.Assert(einstein, checker.Equals, "10 Einstein")
  41. c.Assert(ether, checker.Equals, "10 Ether")
  42. c.Assert(finney, checker.Equals, "10 Finney")
  43. c.Assert(szabo, checker.Equals, "10 Szabo")
  44. c.Assert(shannon, checker.Equals, "10 Shannon")
  45. c.Assert(babbage, checker.Equals, "10 Babbage")
  46. c.Assert(ada, checker.Equals, "10 Ada")
  47. c.Assert(wei, checker.Equals, "10 Wei")
  48. }
  49. func (s *CommonSuite) TestLarge(c *checker.C) {
  50. douglaslarge := CurrencyToString(BigPow(100000000, 43))
  51. adalarge := CurrencyToString(BigPow(100000000, 4))
  52. weilarge := CurrencyToString(big.NewInt(100000000))
  53. c.Assert(douglaslarge, checker.Equals, "10000E298 Douglas")
  54. c.Assert(adalarge, checker.Equals, "10000E7 Einstein")
  55. c.Assert(weilarge, checker.Equals, "100 Babbage")
  56. }