You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

  1. package test
  2. import (
  3. "context"
  4. "math/big"
  5. "testing"
  6. "time"
  7. "github.com/hermeznetwork/hermez-node/eth"
  8. "github.com/stretchr/testify/assert"
  9. "github.com/stretchr/testify/require"
  10. )
  11. func TestClientInterface(t *testing.T) {
  12. var c eth.ClientInterface
  13. client := NewClient(true, 1000)
  14. c = client
  15. require.NotNil(t, c)
  16. }
  17. func TestEthClient(t *testing.T) {
  18. c := NewClient(true, 1000)
  19. block, err := c.EthBlockByNumber(context.TODO(), big.NewInt(3))
  20. assert.Nil(t, err)
  21. assert.Equal(t, uint64(3), block.EthBlockNum)
  22. assert.Equal(t, time.Unix(3, 0), block.Timestamp)
  23. assert.Equal(t, "0x6b0ab5a7a0ebf5f05cef3b49bc7a9739de06469a4e05557d802ee828fdf5187e", block.Hash.Hex())
  24. header, err := c.EthHeaderByNumber(context.TODO(), big.NewInt(4))
  25. assert.Nil(t, err)
  26. assert.Equal(t, big.NewInt(4), header.Number)
  27. assert.Equal(t, uint64(4), header.Time)
  28. assert.Equal(t, "0x66cdb12322040a5a345ad29cea66ca97c14d6142b53987010947c8c008e26913", header.Hash().Hex())
  29. assert.Equal(t, big.NewInt(1000), c.blockNum)
  30. c.Advance()
  31. assert.Equal(t, big.NewInt(1001), c.blockNum)
  32. c.Advance()
  33. assert.Equal(t, big.NewInt(1002), c.blockNum)
  34. c.SetBlockNum(big.NewInt(5000))
  35. assert.Equal(t, big.NewInt(5000), c.blockNum)
  36. c.Advance()
  37. assert.Equal(t, big.NewInt(5001), c.blockNum)
  38. }