Skip to content

Commit

Permalink
test 746 and warn on failed balance fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
cryi committed Jun 21, 2024
1 parent 91f73c6 commit 2ff6cfa
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (engine *rpcCollector) fetchInitialDelegationState(ctx context.Context, del
balanceInfo, err := engine.fetchContractInitialBalanceInfo(ctx, address, blockWithMinimumId, lastBlockInCycle)

if err != nil {
slog.Debug("failed to fetch contract balance info", "address", address.String(), "error", err)
slog.Warn("failed to fetch contract balance info", "address", address.String(), "error", err)

mtx.Lock()
defer mtx.Unlock()
Expand Down
35 changes: 29 additions & 6 deletions core/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ var (
defaultCtx context.Context = context.Background()
)

func getTransport() *test.TestTransport {
transport, err := test.NewTestTransport(http.DefaultTransport, "../test/data/745", "../test/data/745.gob.lz4")
func getTransport(path string) *test.TestTransport {
transport, err := test.NewTestTransport(http.DefaultTransport, path, path+".gob.lz4")
if err != nil {
panic(err)
}
Expand All @@ -28,7 +28,7 @@ func getTransport() *test.TestTransport {
func TestGetActiveDelegates(t *testing.T) {
assert := assert.New(t)

collector, err := newRpcCollector(defaultCtx, []string{"https://eu.rpc.tez.capital/", "https://rpc.tzkt.io/mainnet/"}, getTransport())
collector, err := newRpcCollector(defaultCtx, []string{"https://eu.rpc.tez.capital/", "https://rpc.tzkt.io/mainnet/"}, getTransport("../test/data/745"))
assert.Nil(err)

delegates, err := collector.GetActiveDelegatesFromCycle(defaultCtx, 745)
Expand All @@ -38,15 +38,38 @@ func TestGetActiveDelegates(t *testing.T) {

func TestGetDelegationStateNoStaking(t *testing.T) {
assert := assert.New(t)
debug.SetMaxThreads(1000000)

// cycle 745
cycle := int64(745)
collector, err := newRpcCollector(defaultCtx, []string{"https://eu.rpc.tez.capital/", "https://rpc.tzkt.io/mainnet/"}, getTransport("../test/data/745"))
assert.Nil(err)

debug.SetMaxThreads(1000000)
delegates, err := collector.GetActiveDelegatesFromCycle(defaultCtx, cycle)
assert.Nil(err)

err = runInParallel(defaultCtx, delegates, constants.OGUN_DELEGATE_FETCH_BATCH_SIZE, func(ctx context.Context, addr tezos.Address, mtx *sync.RWMutex) bool {
delegate, err := collector.GetDelegateFromCycle(defaultCtx, cycle, addr)
if err != nil {
assert.Nil(err)
return true
}

collector, err := newRpcCollector(defaultCtx, []string{"https://eu.rpc.tez.capital/", "https://rpc.tzkt.io/mainnet/"}, getTransport())
_, err = collector.GetDelegationState(defaultCtx, delegate, 745)
if err != nil && err != constants.ErrDelegateHasNoMinimumDelegatedBalance {
assert.Nil(err)
return true
}
return false
})
assert.Nil(err)

delegates, err := collector.GetActiveDelegatesFromCycle(defaultCtx, cycle)
// cycle 746
cycle = int64(745)
collector, err = newRpcCollector(defaultCtx, []string{"https://eu.rpc.tez.capital/", "https://rpc.tzkt.io/mainnet/"}, getTransport("../test/data/746"))
assert.Nil(err)

delegates, err = collector.GetActiveDelegatesFromCycle(defaultCtx, cycle)
assert.Nil(err)

err = runInParallel(defaultCtx, delegates, constants.OGUN_DELEGATE_FETCH_BATCH_SIZE, func(ctx context.Context, addr tezos.Address, mtx *sync.RWMutex) bool {
Expand Down
Loading

0 comments on commit 2ff6cfa

Please sign in to comment.