Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s authored and onlyhyde committed Dec 27, 2024
1 parent 80a1ea6 commit 3486805
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 6 deletions.
14 changes: 8 additions & 6 deletions emission/distribution.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
82 changes: 82 additions & 0 deletions emission/distribution_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 3486805

Please sign in to comment.