!5281odin/volume-not-found-quiet → develop05adf998f1

Tests pin VolumeMgr's quiet skip of unswapped pools

AI-generatedEverything on this page was written by an AI agent from the diff: the summaries, the narration, the diagrams, the flags and the glossary. It can be wrong or incomplete, so check it against the code before you rely on it.

1commits
2files
34lines changed
34lines to read
0logic lines (absorbed by develop)
+34test lines

Where the diff is

Look here first

Logic change already on developBase c76dcba75c already has ErrVolumeNotFound and the quiet skip; this MR now adds only tests, unlike its description.manager_volume_current_test.go:252 ↗verify
243243 c.Assert(bucket.AmountRune.String(), Equals, "123")
244244 default:
245245 c.Assert(err, NotNil)
246246 }
247247 }
248248 }
249+
250+// A pool that has never been swapped has no volume record: EndBlock skips it
251+// without logging an error (it did so for every such pool, every block) and
252+// writes nothing for it.
253+func (s *VolumeManagerSuite) TestEndBlockSkipsPoolsWithoutVolume(c *C) {
254+ ctx, mgr := setupManagerForTest(c)
255+
256+ for _, asset := range []common.Asset{common.BTCAsset, common.ETHAsset} {
257+ pool := NewPool()
258+ pool.Asset = asset
259+ c.Assert(mgr.K.SetPool(ctx, pool), IsNil)
260+ }
261+ volume := types.NewVolume(common.BTCAsset)
262+ volume.ChangeRune = cosmos.NewUint(123)
263+ c.Assert(mgr.K.SetVolume(ctx, volume), IsNil)
264+
265+ var logs bytes.Buffer
Message is lowercase, not as describedSentinel in keeper/types is 'total volume not found'; description says 'Total…'. Test pins lowercase text.keeper_volume_test.go:33 ↗careful
2424 err = k.SetVolume(ctx, volume)
2525 c.Assert(err, IsNil)
2626
2727 _, err = k.GetVolume(ctx, common.BTCAsset)
2828 c.Assert(err, IsNil)
2929
3030 _, err = k.GetVolume(ctx, common.ETHAsset)
3131 c.Assert(err, NotNil)
3232 c.Assert(errors.Is(err, kvTypes.ErrVolumeNotFound), Equals, true)
33+ c.Assert(err.Error(), Equals, "total volume not found: pool=ETH.ETH")
3334 }
3435
3536 func (s KeeperVolumeSuite) TestVolumeBucket(c *C) {
3637 ctx, k := setupKeeperForTest(c)
3738
3839 bucket := types.NewVolumeBucket(common.BTCAsset, -1)
3940
4041 err := k.SetVolumeBucket(ctx, bucket)
4142 c.Assert(err, NotNil)
4243
4344 bucket.Index = 0
4445
4546 err = k.SetVolumeBucket(ctx, bucket)
Asserts no 'fail to get volume' logCaptures zerolog output via SdkLogWrapper; regex (?s) spans lines, so any occurrence fails the test.manager_volume_current_test.go:268 ↗look
259+ c.Assert(mgr.K.SetPool(ctx, pool), IsNil)
260+ }
261+ volume := types.NewVolume(common.BTCAsset)
262+ volume.ChangeRune = cosmos.NewUint(123)
263+ c.Assert(mgr.K.SetVolume(ctx, volume), IsNil)
264+
265+ var logs bytes.Buffer
266+ logger := zerolog.New(&logs)
267+ ctx = ctx.WithLogger(thorlog.SdkLogWrapper{Logger: &logger})
268+ c.Assert(mgr.volumeManager.EndBlock(ctx), IsNil)
269+ c.Check(logs.String(), Not(Matches), "(?s).*fail to get volume.*")
270+
271+ // the pool with a volume still rolls over; the other still has none
272+ volume, err := mgr.K.GetVolume(ctx, common.BTCAsset)
273+ c.Assert(err, IsNil)
274+ c.Check(volume.ChangeRune.IsZero(), Equals, true)
275+ c.Check(volume.TotalRune.Uint64(), Equals, uint64(123))
276+ _, err = mgr.K.GetVolume(ctx, common.ETHAsset)
277+ c.Check(err, NotNil)
278+ iterator := mgr.K.GetVolumeBucketIterator(ctx, common.ETHAsset)
279+ c.Check(iterator.Valid(), Equals, false)
280+ c.Assert(iterator.Close(), IsNil)
281+}
Rollover still happens for BTCChangeRune 123 must move into TotalRune; proves the skip doesn't short-circuit the whole loop.manager_volume_current_test.go:272 ↗look
263+ c.Assert(mgr.K.SetVolume(ctx, volume), IsNil)
264+
265+ var logs bytes.Buffer
266+ logger := zerolog.New(&logs)
267+ ctx = ctx.WithLogger(thorlog.SdkLogWrapper{Logger: &logger})
268+ c.Assert(mgr.volumeManager.EndBlock(ctx), IsNil)
269+ c.Check(logs.String(), Not(Matches), "(?s).*fail to get volume.*")
270+
271+ // the pool with a volume still rolls over; the other still has none
272+ volume, err := mgr.K.GetVolume(ctx, common.BTCAsset)
273+ c.Assert(err, IsNil)
274+ c.Check(volume.ChangeRune.IsZero(), Equals, true)
275+ c.Check(volume.TotalRune.Uint64(), Equals, uint64(123))
276+ _, err = mgr.K.GetVolume(ctx, common.ETHAsset)
277+ c.Check(err, NotNil)
278+ iterator := mgr.K.GetVolumeBucketIterator(ctx, common.ETHAsset)
279+ c.Check(iterator.Valid(), Equals, false)
280+ c.Assert(iterator.Close(), IsNil)
281+}
Unswapped pool gets no bucketsChecks ETH still has no volume and an empty bucket iterator, so EndBlock wrote nothing for it.manager_volume_current_test.go:278 ↗look
269+ c.Check(logs.String(), Not(Matches), "(?s).*fail to get volume.*")
270+
271+ // the pool with a volume still rolls over; the other still has none
272+ volume, err := mgr.K.GetVolume(ctx, common.BTCAsset)
273+ c.Assert(err, IsNil)
274+ c.Check(volume.ChangeRune.IsZero(), Equals, true)
275+ c.Check(volume.TotalRune.Uint64(), Equals, uint64(123))
276+ _, err = mgr.K.GetVolume(ctx, common.ETHAsset)
277+ c.Check(err, NotNil)
278+ iterator := mgr.K.GetVolumeBucketIterator(ctx, common.ETHAsset)
279+ c.Check(iterator.Valid(), Equals, false)
280+ c.Assert(iterator.Close(), IsNil)
281+}

Ask an AI about this change

Chat assistantClaude, ChatGPT, … (reads a link)

Coding agentClaude Code, Cursor, … (reads the repo)

The context file is context.md. Use Copy with context for an AI that can't open links; it pastes the whole file in.

Glossary

Derived pool
THOR.* pools priced from layer-1 pools and never swapped directly, so they have no volume record.
EndBlock
Code run at the end of every block; anything here costs every node, every block.
ErrVolumeNotFound
Sentinel in keeper/types that GetVolume wraps when a pool has no volume record yet. keeper/types/types.go ↗
VolumeMgr
Manager that rolls each pool's 24h swap volume across time buckets in EndBlock. manager_volume_current.go ↗