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.

57 lines
1.7 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.
4 years ago
  1. package priceupdater
  2. import (
  3. "context"
  4. "math/big"
  5. "os"
  6. "testing"
  7. ethCommon "github.com/ethereum/go-ethereum/common"
  8. "github.com/hermeznetwork/hermez-node/common"
  9. dbUtils "github.com/hermeznetwork/hermez-node/db"
  10. "github.com/hermeznetwork/hermez-node/db/historydb"
  11. "github.com/hermeznetwork/hermez-node/test"
  12. "github.com/stretchr/testify/assert"
  13. "github.com/stretchr/testify/require"
  14. )
  15. func TestPriceUpdater(t *testing.T) {
  16. // Init DB
  17. pass := os.Getenv("POSTGRES_PASS")
  18. db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
  19. assert.NoError(t, err)
  20. historyDB := historydb.NewHistoryDB(db, db, nil)
  21. // Clean DB
  22. test.WipeDB(historyDB.DB())
  23. // Populate DB
  24. // Gen blocks and add them to DB
  25. blocks := test.GenBlocks(1, 2)
  26. assert.NoError(t, historyDB.AddBlocks(blocks))
  27. // Gen tokens and add them to DB
  28. tokens := []common.Token{}
  29. tokens = append(tokens, common.Token{
  30. TokenID: 1,
  31. EthBlockNum: blocks[0].Num,
  32. EthAddr: ethCommon.BigToAddress(big.NewInt(2)),
  33. Name: "DAI",
  34. Symbol: "DAI",
  35. Decimals: 18,
  36. })
  37. assert.NoError(t, historyDB.AddTokens(tokens))
  38. // Init price updater
  39. pu, err := NewPriceUpdater("https://api-pub.bitfinex.com/v2/", APITypeBitFinexV2, historyDB)
  40. require.NoError(t, err)
  41. // Update token list
  42. assert.NoError(t, pu.UpdateTokenList())
  43. // Update prices
  44. pu.UpdatePrices(context.Background())
  45. // Check that prices have been updated
  46. fetchedTokens, err := historyDB.GetTokensTest()
  47. require.NoError(t, err)
  48. // TokenID 0 (ETH) is always on the DB
  49. assert.Equal(t, 2, len(fetchedTokens))
  50. for _, token := range fetchedTokens {
  51. assert.NotNil(t, token.USD)
  52. assert.NotNil(t, token.USDUpdate)
  53. }
  54. }