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.

55 lines
1.6 KiB

Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
3 years ago
  1. package priceupdater
  2. import (
  3. "math/big"
  4. "os"
  5. "testing"
  6. ethCommon "github.com/ethereum/go-ethereum/common"
  7. "github.com/hermeznetwork/hermez-node/common"
  8. dbUtils "github.com/hermeznetwork/hermez-node/db"
  9. "github.com/hermeznetwork/hermez-node/db/historydb"
  10. "github.com/hermeznetwork/hermez-node/test"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestPriceUpdater(t *testing.T) {
  14. // Init DB
  15. pass := os.Getenv("POSTGRES_PASS")
  16. db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
  17. assert.NoError(t, err)
  18. historyDB := historydb.NewHistoryDB(db)
  19. // Clean DB
  20. test.WipeDB(historyDB.DB())
  21. // Populate DB
  22. // Gen blocks and add them to DB
  23. blocks := test.GenBlocks(1, 2)
  24. assert.NoError(t, historyDB.AddBlocks(blocks))
  25. // Gen tokens and add them to DB
  26. tokens := []common.Token{}
  27. tokens = append(tokens, common.Token{
  28. TokenID: 1,
  29. EthBlockNum: blocks[0].Num,
  30. EthAddr: ethCommon.BigToAddress(big.NewInt(2)),
  31. Name: "DAI",
  32. Symbol: "DAI",
  33. Decimals: 18,
  34. })
  35. assert.NoError(t, historyDB.AddTokens(tokens))
  36. // Init price updater
  37. pu := NewPriceUpdater("https://api-pub.bitfinex.com/v2/", historyDB)
  38. // Update token list
  39. assert.NoError(t, pu.UpdateTokenList())
  40. // Update prices
  41. pu.UpdatePrices()
  42. // Check that prices have been updated
  43. limit := uint(10)
  44. fetchedTokens, _, err := historyDB.GetTokens(nil, nil, "", nil, &limit, historydb.OrderAsc)
  45. assert.NoError(t, err)
  46. // TokenID 0 (ETH) is always on the DB
  47. assert.Equal(t, 2, len(fetchedTokens))
  48. for _, token := range fetchedTokens {
  49. assert.NotNil(t, token.USD)
  50. assert.NotNil(t, token.USDUpdate)
  51. }
  52. }