Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion contract/r/gnoswap/community_pool/community_pool.gno
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func GetBalanceOf(tokenPath string) int64 {
//
// Only callable by admin or governance.
func TransferToken(cur realm, tokenPath string, to address, amount int64) {
halt.AssertIsNotHaltedCommunityPool()
halt.AssertIsNotHaltedWithdraw()
Comment thread
jinoosss marked this conversation as resolved.

prevRealm := runtime.PreviousRealm()
Expand Down
5 changes: 2 additions & 3 deletions contract/r/gnoswap/community_pool/community_pool_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ func TestCommunityPool_TransferToken(t *testing.T) {
to: dummyReceiver,
amount: 1000,
shouldPanic: true,
panicMsg: "halted: community_pool",
panicMsg: "halted: withdraw",
},
{
name: "panic if halted with safe mode (withdraw blocked)",
name: "panic if halted with safe mode (withdraw blocked only)",
setup: func() {
testing.SetRealm(adminRealm)
halt.SetHaltLevel(cross, halt.HaltLevelSafeMode)
},
caller: adminRealm,
tokenPath: gnsPath,
to: dummyReceiver,
amount: 1000,
Expand Down
1 change: 0 additions & 1 deletion contract/r/gnoswap/emission/emission.gno
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ func MintAndDistributeGns(cur realm) (int64, bool) {
// Only callable by admin or governance.
func SetDistributionStartTime(cur realm, startTimestamp int64) {
halt.AssertIsNotHaltedEmission()
halt.AssertIsNotHaltedWithdraw()

caller := runtime.PreviousRealm().Address()
access.AssertIsAdminOrGovernance(caller)
Expand Down
1 change: 1 addition & 0 deletions contract/r/gnoswap/gnft/_helper_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func setHalted(halted bool) {
adminAddr, _ := access.GetAddress(prbac.ROLE_ADMIN.String())
testing.SetRealm(testing.NewUserRealm(adminAddr))
halt.SetOperationStatus(cross, halt.OpTypePosition, halted)
halt.SetOperationStatus(cross, halt.OpTypeWithdraw, halted)
}

// tid is a test helper function that converts uint64 to TokenID
Expand Down
13 changes: 0 additions & 13 deletions contract/r/gnoswap/gnft/gnft.gno
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about removing halt from gnft?
It seems better for nft to function as a neutral resource rather than being included in the domain.

Can you share your thoughts? @dongwon8247

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"gno.land/p/demo/tokens/grc721"
ufmt "gno.land/p/nt/ufmt/v0"
"gno.land/r/gnoswap/access"
"gno.land/r/gnoswap/halt"

prabc "gno.land/p/gnoswap/rbac"
_ "gno.land/r/gnoswap/rbac"
Expand Down Expand Up @@ -74,8 +73,6 @@ func MustOwnerOf(tid grc721.TokenID) address {
//
// Only callable by position contract.
func SetTokenURI(cur realm, tid grc721.TokenID, tURI grc721.TokenURI) (bool, error) {
halt.AssertIsNotHaltedPosition()

caller := runtime.PreviousRealm().Address()
access.AssertIsPosition(caller)

Expand All @@ -96,8 +93,6 @@ func SetTokenURI(cur realm, tid grc721.TokenID, tURI grc721.TokenURI) (bool, err
// Returns error if transfer fails.
// Only callable by staker contract.
func SafeTransferFrom(cur realm, from, to address, tid grc721.TokenID) error {
halt.AssertIsNotHaltedPosition()

caller := runtime.PreviousRealm().Address()
access.AssertIsStaker(caller)

Expand All @@ -119,8 +114,6 @@ func SafeTransferFrom(cur realm, from, to address, tid grc721.TokenID) error {
// Returns error if transfer fails.
// Only callable by staker contract.
func TransferFrom(cur realm, from, to address, tid grc721.TokenID) error {
halt.AssertIsNotHaltedPosition()

caller := runtime.PreviousRealm().Address()
access.AssertIsStaker(caller)

Expand All @@ -141,7 +134,6 @@ func TransferFrom(cur realm, from, to address, tid grc721.TokenID) error {
// Returns error if approval fails.
// Only callable when not halted.
func Approve(cur realm, approved address, tid grc721.TokenID) error {
halt.AssertIsNotHaltedPosition()
assertIsValidAddress(approved)

err := nft.Approve(approved, tid)
Expand All @@ -158,7 +150,6 @@ func Approve(cur realm, approved address, tid grc721.TokenID) error {
// Returns error if operation fails.
// Only callable when not halted.
func SetApprovalForAll(cur realm, operator address, approved bool) error {
halt.AssertIsNotHaltedPosition()
assertIsValidAddress(operator)

checkErr(nft.SetApprovalForAll(operator, approved))
Expand Down Expand Up @@ -195,8 +186,6 @@ func IsApprovedForAll(owner, operator address) bool {
// Returns minted token ID.
// Only callable by position contract.
func Mint(cur realm, to address, tid grc721.TokenID) grc721.TokenID {
halt.AssertIsNotHaltedPosition()

caller := runtime.PreviousRealm().Address()
access.AssertIsPosition(caller)

Expand Down Expand Up @@ -226,8 +215,6 @@ func Exists(tid grc721.TokenID) bool {
//
// Only callable by position.
func Burn(cur realm, tid grc721.TokenID) {
halt.AssertIsNotHaltedPosition()

caller := runtime.PreviousRealm().Address()
access.AssertIsPosition(caller)

Expand Down
134 changes: 0 additions & 134 deletions contract/r/gnoswap/gnft/gnft_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -1168,140 +1168,6 @@ func TestApprove(t *testing.T) {
}
}

func TestHaltedOperations(t *testing.T) {
tests := []struct {
name string
operation string
setup func()
shouldPanic bool
panicMsg string
}{
{
name: "Mint when halted",
operation: "Mint",
setup: func() {
resetObject(t)
setHalted(true)
},
shouldPanic: true,
panicMsg: "halted: position",
},
{
name: "Burn when halted",
operation: "Burn",
setup: func() {
resetObject(t)
testing.SetRealm(positionRealm)
Mint(cross, addr01, tid(1))
setHalted(true)
},
shouldPanic: true,
panicMsg: "halted: position",
},
{
name: "SafeTransferFrom when halted",
operation: "SafeTransferFrom",
setup: func() {
resetObject(t)
testing.SetRealm(positionRealm)
Mint(cross, addr01, tid(1))
testing.SetRealm(addr01Realm)
Approve(cross, stakerRealm.Address(), tid(1))
setHalted(true)
},
shouldPanic: true,
panicMsg: "halted: position",
},
{
name: "TransferFrom when halted",
operation: "TransferFrom",
setup: func() {
resetObject(t)
testing.SetRealm(positionRealm)
Mint(cross, addr01, tid(1))
testing.SetRealm(addr01Realm)
Approve(cross, stakerRealm.Address(), tid(1))
setHalted(true)
},
shouldPanic: true,
panicMsg: "halted: position",
},
{
name: "Approve when halted",
operation: "Approve",
setup: func() {
resetObject(t)
testing.SetRealm(positionRealm)
Mint(cross, addr01, tid(1))
setHalted(true)
},
shouldPanic: true,
panicMsg: "halted: position",
},
{
name: "SetApprovalForAll when halted",
operation: "SetApprovalForAll",
setup: func() {
resetObject(t)
setHalted(true)
},
shouldPanic: true,
panicMsg: "halted: position",
},
{
name: "SetTokenURI when halted",
operation: "SetTokenURI",
setup: func() {
resetObject(t)
testing.SetRealm(positionRealm)
Mint(cross, addr01, tid(1))
setHalted(true)
},
shouldPanic: true,
panicMsg: "halted: position",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.setup != nil {
tt.setup()
}

if tt.shouldPanic {
uassert.AbortsWithMessage(t, tt.panicMsg, func() {
switch tt.operation {
case "Mint":
testing.SetRealm(positionRealm)
Mint(cross, addr01, tid(1))
case "Burn":
testing.SetRealm(positionRealm)
Burn(cross, tid(1))
case "SafeTransferFrom":
testing.SetRealm(stakerRealm)
SafeTransferFrom(cross, addr01, addr02, tid(1))
case "TransferFrom":
testing.SetRealm(stakerRealm)
TransferFrom(cross, addr01, addr02, tid(1))
case "Approve":
testing.SetRealm(addr01Realm)
Approve(cross, addr02, tid(1))
case "SetApprovalForAll":
testing.SetRealm(addr01Realm)
SetApprovalForAll(cross, addr02, true)
case "SetTokenURI":
testing.SetRealm(positionRealm)
SetTokenURI(cross, tid(1), "test-uri")
}
})
}

// Cleanup: unhalt for next test
setHalted(false)
})
}
}

func Test_setTokenURI(t *testing.T) {
tests := []struct {
name string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func (gv *governanceV1) ProposeCommunityPoolSpend(
amount int64,
) (newProposalId int64) {
halt.AssertIsNotHaltedGovernance()
halt.AssertIsNotHaltedWithdraw()

assertIsValidToken(tokenPath)

Expand Down
1 change: 0 additions & 1 deletion contract/r/gnoswap/gov/staker/v1/staker_delegate.gno
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ func (gs *govStakerV1) Redelegate(
// Allows users to collect GNS tokens that completed undelegation lockup period.
// Burns xGNS and returns GNS tokens.
func (gs *govStakerV1) CollectUndelegatedGns() int64 {
halt.AssertIsNotHaltedGovStaker()
halt.AssertIsNotHaltedWithdraw()

prevRealm := runtime.PreviousRealm()
Expand Down
23 changes: 23 additions & 0 deletions contract/r/gnoswap/gov/staker/v1/staker_delegate_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"gno.land/r/gnoswap/gns"
"gno.land/r/gnoswap/gov/xgns"
"gno.land/r/gnoswap/halt"
)

// Test Delegate function
Expand Down Expand Up @@ -708,6 +709,28 @@ func TestStakerDelegate_CollectUndelegatedGns(t *testing.T) {
}
}

func TestStakerDelegate_CollectUndelegatedGns_EmergencyHaltAllowsRecovery(t *testing.T) {
gs := createTestGovStaker()
cleanupStakerDelegateTest(t, gs)
setupStakerDelegateTestCollectableAmount(t, gs, testutils.TestAddress("alice"), minimumAmount)
defer cleanupStakerDelegateTest(t, gs)

testing.SetRealm(adminRealm)
halt.SetHaltLevel(cross, halt.HaltLevelEmergency)

testing.SetRealm(testing.NewUserRealm(testutils.TestAddress("alice")))
uassert.NotPanics(t, func() {
func(cur realm) {
testing.SetRealm(testing.NewCodeRealm(GOV_STAKER_PKG_PATH))
result := gs.CollectUndelegatedGns()
uassert.Equal(t, int64(minimumAmount), result)
}(cross)
})

testing.SetRealm(adminRealm)
halt.SetHaltLevel(cross, halt.HaltLevelNone)
Comment thread
jinoosss marked this conversation as resolved.
}

// Test comprehensive delegation validation including edge cases
func TestStakerDelegate_DelegationValidationEdgeCases(t *testing.T) {
// Initialize gov staker
Expand Down
9 changes: 5 additions & 4 deletions contract/r/gnoswap/gov/staker/v1/staker_reward.gno
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
// No parameters required - automatically determines caller's rewards.
// Transfers rewards directly to caller.
func (gs *govStakerV1) CollectReward() {
halt.AssertIsNotHaltedGovStaker()
halt.AssertIsNotHaltedWithdraw()

caller := runtime.PreviousRealm().Address()
Expand Down Expand Up @@ -97,7 +96,6 @@ func (gs *govStakerV1) CollectReward() {
//
// Only callable by launchpad contract.
func (gs *govStakerV1) CollectRewardFromLaunchPad(to address) {
halt.AssertIsNotHaltedGovStaker()
halt.AssertIsNotHaltedWithdraw()

caller := runtime.PreviousRealm().Address()
Expand Down Expand Up @@ -170,8 +168,11 @@ func (gs *govStakerV1) CollectRewardFromLaunchPad(to address) {
// - if system is halted for withdrawals
// - if access control operations fail
func (gs *govStakerV1) SetAmountByProjectWallet(addr address, amount int64, add bool) {
halt.AssertIsNotHaltedGovStaker()
halt.AssertIsNotHaltedWithdraw()
if add {
halt.AssertIsNotHaltedGovStaker()
} else {
halt.AssertIsNotHaltedWithdraw()
}

caller := runtime.PreviousRealm().Address()
currentTimestamp := time.Now().Unix()
Expand Down
Loading