2022-06-01 12:57:28 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2021-2024 Status Research & Development GmbH
|
2022-06-01 12:57:28 +00:00
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2024-02-29 13:24:08 +00:00
|
|
|
{.push raises: [].}
|
2020-04-26 16:26:53 +00:00
|
|
|
{.used.}
|
|
|
|
|
2020-03-24 11:13:07 +00:00
|
|
|
import
|
2021-04-28 16:41:02 +00:00
|
|
|
unittest2,
|
2023-05-15 05:05:12 +00:00
|
|
|
../beacon_chain/el/[el_conf, el_manager],
|
2021-04-28 16:41:02 +00:00
|
|
|
./testutil
|
2020-03-24 11:13:07 +00:00
|
|
|
|
2020-11-05 23:11:06 +00:00
|
|
|
suite "Eth1 monitor":
|
2023-03-14 15:40:37 +00:00
|
|
|
test "Rewrite URLs":
|
2020-11-05 23:11:06 +00:00
|
|
|
var
|
2020-11-12 13:49:13 +00:00
|
|
|
gethHttpUrl = "http://localhost:8545"
|
|
|
|
gethHttpsUrl = "https://localhost:8545"
|
|
|
|
gethWsUrl = "ws://localhost:8545"
|
|
|
|
unspecifiedProtocolUrl = "localhost:8545"
|
|
|
|
|
|
|
|
fixupWeb3Urls gethHttpUrl
|
|
|
|
fixupWeb3Urls gethHttpsUrl
|
|
|
|
fixupWeb3Urls gethWsUrl
|
|
|
|
fixupWeb3Urls unspecifiedProtocolUrl
|
2020-11-05 23:11:06 +00:00
|
|
|
|
|
|
|
check:
|
2022-01-15 07:11:17 +00:00
|
|
|
gethHttpUrl == "http://localhost:8545"
|
|
|
|
gethHttpsUrl == "https://localhost:8545"
|
|
|
|
unspecifiedProtocolUrl == "ws://localhost:8545"
|
2020-11-12 13:49:13 +00:00
|
|
|
|
|
|
|
gethWsUrl == "ws://localhost:8545"
|
2022-01-03 12:22:56 +00:00
|
|
|
|
2022-08-12 13:52:06 +00:00
|
|
|
test "Deposits chain":
|
|
|
|
var
|
|
|
|
chain = Eth1Chain()
|
|
|
|
depositIndex = 0.uint64
|
|
|
|
for i in 0 ..< (MAX_DEPOSITS + 1) * 3:
|
|
|
|
var deposits = newSeqOfCap[DepositData](i)
|
|
|
|
for _ in 0 ..< i mod (MAX_DEPOSITS + 1):
|
|
|
|
deposits.add DepositData(amount: depositIndex.Gwei)
|
|
|
|
inc depositIndex
|
|
|
|
|
|
|
|
const interval = defaultRuntimeConfig.SECONDS_PER_ETH1_BLOCK
|
|
|
|
chain.blocks.addLast Eth1Block(
|
|
|
|
number: i.Eth1BlockNumber,
|
|
|
|
timestamp: i.Eth1BlockTimestamp * interval,
|
|
|
|
deposits: deposits,
|
|
|
|
depositCount: depositIndex)
|
|
|
|
|
|
|
|
proc doTest(first, last: uint64) =
|
|
|
|
var idx = first
|
|
|
|
for data in chain.getDepositsRange(first, last):
|
|
|
|
check data.amount == idx.Gwei
|
|
|
|
inc idx
|
|
|
|
check idx == last
|
|
|
|
|
|
|
|
for i in 0 .. depositIndex:
|
|
|
|
for j in i .. depositIndex:
|
2024-08-22 14:12:03 +00:00
|
|
|
doTest(i, j)
|