diff --git a/emission/distribution.gno b/emission/distribution.gno index eeb6ce8d..d2cc02c2 100644 --- a/emission/distribution.gno +++ b/emission/distribution.gno @@ -151,11 +151,13 @@ func distributeToTarget(amount uint64) uint64 { totalSent += distAmount transferToTarget(targetInt, distAmount) + + return false }) - leftGNSAmount := amount - totalSent + leftAmount := amount - totalSent if leftGNSAmount > 0 { - setLeftGNSAmount(leftGNSAmount) + setLeftGNSAmount(leftAmount) } return totalSent @@ -245,14 +247,14 @@ func GetAccuDistributedToGovStaker() uint64 { return accuDistributedToGovStaker } -func SetDistributedToStaker(amount uint64) { +func ClearDistributedToStaker() { assertStakerOnly() - distributedToStaker = amount + distributedToStaker = 0 } -func SetDistributedToGovStaker(amount uint64) { +func ClearDistributedToGovStaker() { assertOnlyGovStaker() - distributedToGovStaker = amount + distributedToGovStaker = 0 } func setDistributionBpsPct(target int, pct uint64) { diff --git a/emission/distribution_test.gno b/emission/distribution_test.gno index 659bee65..a2deb2bf 100644 --- a/emission/distribution_test.gno +++ b/emission/distribution_test.gno @@ -362,6 +362,88 @@ func TestDistributeToTarget(t *testing.T) { } } +func TestClearDistributedToStaker(t *testing.T) { + distributedToStaker = 100 + + tests := []struct { + name string + expected uint64 + callerRealm std.Realm + shouldPanic bool + panicMsg string + }{ + { + name: "can not clear is caller is not staker", + shouldPanic: true, + panicMsg: `caller(g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm) has no permission`, + }, + { + name: "can clear if caller is staker", + callerRealm: stakerRealm, + expected: 0, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if tt.callerRealm != (std.Realm{}) { + std.TestSetRealm(tt.callerRealm) + } + + if tt.shouldPanic { + uassert.PanicsWithMessage(t, tt.panicMsg, func() { + ClearDistributedToStaker() + }) + } else { + ClearDistributedToStaker() + uassert.Equal(t, uint64(0), distributedToStaker) + } + }) + } + +} + +func TestClearClearDistributedToGovStaker(t *testing.T) { + distributedToGovStaker = 100 + + tests := []struct { + name string + expected uint64 + callerRealm std.Realm + shouldPanic bool + panicMsg string + }{ + { + name: "can not clear is caller is not gov/staker", + shouldPanic: true, + panicMsg: `caller(g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm) has no permission`, + }, + { + name: "can clear if caller is gov/taker", + callerRealm: govStakerRealm, + expected: 0, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if tt.callerRealm != (std.Realm{}) { + std.TestSetRealm(tt.callerRealm) + } + + if tt.shouldPanic { + uassert.PanicsWithMessage(t, tt.panicMsg, func() { + ClearDistributedToGovStaker() + }) + } else { + ClearDistributedToGovStaker() + uassert.Equal(t, uint64(0), distributedToGovStaker) + } + }) + } + +} + func sliceToFourInt(t *testing.T, slice []int) (int, int, int, int) { t.Helper()