Skip to content

Commit

Permalink
fix: remove TestSet helpers in logic code
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s committed Aug 7, 2023
1 parent c823fe0 commit 807ef16
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 26 deletions.
1 change: 1 addition & 0 deletions .base/bar/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/bar
1 change: 1 addition & 0 deletions .base/foo/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/foo
6 changes: 2 additions & 4 deletions .base/gnft/gnft.gno
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,11 @@ func SetApprovalForAll(user users.AddressOrName, approved bool) {
}
}

func TransferFrom(from, to users.AddressOrName, tid grc721.TokenID) bool {
func TransferFrom(from, to users.AddressOrName, tid grc721.TokenID) {
err := nft.TransferFrom(from.Resolve(), to.Resolve(), tid)
if err != nil {
return false
panic(err)
}

return true
}

// Admin
Expand Down
1 change: 1 addition & 0 deletions .base/gnft/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/gnft
1 change: 1 addition & 0 deletions .base/gnos/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/gnos
11 changes: 8 additions & 3 deletions .makefile/3_staker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ ADDR_STAKER := g13h5s9utqcwg3a655njen0p89txusjpfrs3vxp8
TX_EXPIRE := 9999999999

NOW := $(shell date +%s)
INCENTIVE_START := $(shell expr $(NOW) + 35)
INCENTIVE_END := $(shell expr $(NOW) + 60)
INCENTIVE_START := $(shell expr $(NOW) + 60)
INCENTIVE_END := $(shell expr $(NOW) + 100)


MAKEFILE := 3_staker.mk
Expand Down Expand Up @@ -49,7 +49,7 @@ approve: approve-lp01 approve-lp02 approve-tr01
pool: pool-init pool-create

.PHONY: mint
mint: mint-01 own-01
mint: mint-01 own-01 approve-01

.PHONY: staker
staker: create-incentive stake-token claim-reward unstake-token withdraw-token
Expand Down Expand Up @@ -184,6 +184,11 @@ own-01:
@echo NFT tokenId 1 Owner: $(shell curl -s 'http://localhost:26657/abci_query?path=%22vm/qeval%22&data=%22gno.land/r/gnft\nOwnerOf(\"1\")%22' | jq -r ".result.response.ResponseBase.Data" | base64 -d | awk -F'[ ()]' '{print $$2}')
@echo

approve-01:
$(info ************ [Approve] approve staker contract to spend tokenId 1 ************)
@echo "" | gnokey maketx call -pkgpath gno.land/r/gnft -func Approve -args $(ADDR_STAKER) -args "1" -insecure-password-stdin=true -remote localhost:26657 -broadcast=true -chainid dev -gas-fee 1ugnot -gas-wanted 9000000 -memo "" lp01 > /dev/null



## STAKER
create-incentive:
Expand Down
6 changes: 5 additions & 1 deletion .makefile/4_pool_position_staker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ approve: approve-lp01 approve-tr01
pool: pool-init pool-create

.PHONY: mint
mint: mint-01 own-01
mint: mint-01 own-01 approve-01

.PHONY: pps
pps: staker-create-incentive staker-stake-token pool-set-protocol-fee pool-swap-fee-01 position-collect-01 pool-swap-fee-10 position-collect-10 pool-collect-protocol-fee staker-claim-reward staker-unstake-withdraw position-nft-burn chk-lp01
Expand Down Expand Up @@ -165,6 +165,10 @@ own-01:
@echo NFT tokenId 1 Owner: $(shell curl -s 'http://localhost:26657/abci_query?path=%22vm/qeval%22&data=%22gno.land/r/gnft\nOwnerOf(\"1\")%22' | jq -r ".result.response.ResponseBase.Data" | base64 -d | awk -F'[ ()]' '{print $$2}')
@echo

approve-01:
$(info ************ [GNFT] approve staker contract to spend tokenId 1 ************)
@echo "" | gnokey maketx call -pkgpath gno.land/r/gnft -func Approve -args $(ADDR_STAKER) -args "1" -insecure-password-stdin=true -remote localhost:26657 -broadcast=true -chainid dev -gas-fee 1ugnot -gas-wanted 9000000 -memo "" lp01 > /dev/null


## PPS
staker-create-incentive:
Expand Down
1 change: 1 addition & 0 deletions pool/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/pool
1 change: 1 addition & 0 deletions position/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/position
1 change: 1 addition & 0 deletions staker/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/staker
16 changes: 4 additions & 12 deletions staker/staker.gno
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,9 @@ func WithdrawToken(tokenId string, to std.Address) {
// delete(deposits, tokenId)
deposits.Remove(tokenId)

// grc721 should use PrevRealm()
_orig := std.GetOrigCaller() // XXX
std.TestSetOrigCaller(GetOrigPkgAddr()) // XXX
nto := nft.TransferFrom(a2u(PrevRealmAddr()), a2u(to), tid(tokenId))
if !nto {
panic("NFT TransferFrom Failed #2")
}
std.TestSetOrigCaller(_orig) // XXX
// xxx grc721 should use PrevRealm()
// approve then transfer (approve in testcase)
nft.TransferFrom(a2u(GetOrigPkgAddr()), a2u(to), tid(tokenId))
}

func ClaimReward(
Expand Down Expand Up @@ -602,8 +597,5 @@ func transferDeposit(tokenId string, to std.Address) {
deposits.Set(tokenId, update)

// transfer actual NFT
nto := nft.TransferFrom(a2u(owner), a2u(to), tid(tokenId)) // nft transfer ok
if !nto {
panic("NFT TransferFrom Failed #1")
}
nft.TransferFrom(a2u(owner), a2u(to), tid(tokenId)) // nft transfer ok
}
11 changes: 5 additions & 6 deletions staker/staker_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ package staker
import (
"std"
"testing"
"time"

"gno.land/p/demo/testutils"
"gno.land/r/demo/users"

bar "gno.land/r/bar"
foo "gno.land/r/foo"

p "gno.land/r/pool"
s "gno.land/r/position"
Expand Down Expand Up @@ -75,6 +70,10 @@ func TestPositionMint(t *testing.T) {

shouldEQ(t, tPosTokenId, "1")
shouldEQ(t, nft.OwnerOf("1"), GetOrigCaller()) // lp01

// approve nft to staker
std.TestSetPrevAddr(lp01)
nft.Approve(a2u(GetOrigPkgAddr()), "1")
}

func TestCreateIncentive(t *testing.T) {
Expand All @@ -86,7 +85,7 @@ func TestCreateIncentive(t *testing.T) {
)

// nft owner doesn't change yet
shouldEQ(t, nft.OwnerOf("1"), lp01) // lp01
shouldEQ(t, nft.OwnerOf("1"), lp01) // lp0
}

func TestStakeToken(t *testing.T) {
Expand Down

0 comments on commit 807ef16

Please sign in to comment.