Skip to content

Commit

Permalink
fix: test case modified and bug fix
Browse files Browse the repository at this point in the history
- bug:
When receiving a reward, check if the amount of GNS held by the GOV STAKER is more than the amount of reward that should be paid.
  • Loading branch information
onlyhyde committed Jan 7, 2025
1 parent 942d2bd commit 2f83ac9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gov/staker/staker.gno
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func collectEmissionReward(addr std.Address) uint64 {
return 0
}

govStakerGnsBalance := xgns.BalanceOf(a2u(consts.GOV_STAKER_ADDR))
govStakerGnsBalance := gns.BalanceOf(a2u(consts.GOV_STAKER_ADDR))
if govStakerGnsBalance < emissionReward {
panic(addDetailToError(
errNotEnoughBalance,
Expand Down
12 changes: 9 additions & 3 deletions gov/staker/staker_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -382,19 +382,25 @@ func TestProtocolFee(t *testing.T) {
}

func TestRedelegate(t *testing.T) {
// assume realm user
std.TestSetRealm(userRealm)
std.TestSetRealm(std.NewCodeRealm(consts.EMISSION_PATH))
std.TestSkipHeights(100)
gns.MintGns(a2u(userRealm.Addr())) // 2M gns

// user has xGNS from previous test (some minted)
// try re-delegating
std.TestSetRealm(userRealm)
from := userRealm.Addr()
to := makeFakeAddress("validator_1")
println("to", to)
amount := uint64(1_000_000)

std.TestSetOrigCaller(userRealm.Addr())
gns.Approve(a2u(consts.GOV_STAKER_ADDR), amount)
Delegate(to, amount)

std.TestSetOrigCaller(userRealm.Addr())
gns.Approve(a2u(consts.GOV_STAKER_ADDR), amount)
Redelegate(from, to, amount)

// check data: user xGNS must remain the same, but from-> to shift in staker structure?

// not enough xGNS => panic
Expand Down

0 comments on commit 2f83ac9

Please sign in to comment.