Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update std Functions to Follow main Branch of gno #539

Merged
merged 11 commits into from
Feb 20, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/run_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: gnolang/gno
ref: ec696d40ae44eee809e3ca2c7cdb2ce4c6eece04
ref: master
path: ./gno

- name: Set up Go
Expand Down
26 changes: 13 additions & 13 deletions contract/p/gnoswap/halt/level_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestBasicHaltLevel_IsOperationAllowed(t *testing.T) {
name: "should allow swap operation when configured",
level: BasicHaltLevel{
baseInfo: baseInfo{name: "test", desc: "test level"},
level: 1,
level: 1,
allowedOps: allowedOps{OpTypeSwap: true},
},
operation: NewOperation(OpTypeSwap, "test swap", "swap operation"),
Expand All @@ -25,7 +25,7 @@ func TestBasicHaltLevel_IsOperationAllowed(t *testing.T) {
name: "should not allow swap operation when not configured",
level: BasicHaltLevel{
baseInfo: baseInfo{name: "test", desc: "test level"},
level: 1,
level: 1,
allowedOps: allowedOps{OpTypeLiquidity: true},
},
operation: NewOperation(OpTypeSwap, "test swap", "swap operation"),
Expand All @@ -35,7 +35,7 @@ func TestBasicHaltLevel_IsOperationAllowed(t *testing.T) {
name: "should not allow operation when allowed is false",
level: BasicHaltLevel{
baseInfo: baseInfo{name: "test", desc: "test level"},
level: 1,
level: 1,
allowedOps: allowedOps{OpTypeSwap: false},
},
operation: NewOperation(OpTypeSwap, "test swap", "swap operation"),
Expand All @@ -44,8 +44,8 @@ func TestBasicHaltLevel_IsOperationAllowed(t *testing.T) {
{
name: "should handle multiple operations correctly",
level: BasicHaltLevel{
baseInfo: baseInfo{name: "test", desc: "test level"},
level: 1,
baseInfo: baseInfo{name: "test", desc: "test level"},
level: 1,
allowedOps: allowedOps{
OpTypeSwap: true,
OpTypeLiquidity: true,
Expand All @@ -70,12 +70,12 @@ func TestCompositeHaltLevel_IsOperationAllowed(t *testing.T) {
// basic levels
level1 := BasicHaltLevel{
baseInfo: baseInfo{name: "level1", desc: "test level 1"},
level: 1,
level: 1,
allowedOps: allowedOps{OpTypeSwap: true, OpTypeLiquidity: false},
}
level2 := BasicHaltLevel{
baseInfo: baseInfo{name: "level2", desc: "test level 2"},
level: 2,
level: 2,
allowedOps: allowedOps{OpTypeSwap: false, OpTypeLiquidity: true},
}

Expand All @@ -88,12 +88,12 @@ func TestCompositeHaltLevel_IsOperationAllowed(t *testing.T) {
{
name: "AND operator - should return true when all levels allow",
composite: CompositeHaltLevel{
baseInfo: baseInfo{name: "composite and", desc: "test composite and"},
levels: HaltLevels{
baseInfo: baseInfo{name: "composite and", desc: "test composite and"},
levels: HaltLevels{
level1,
BasicHaltLevel{
baseInfo: baseInfo{name: "level3", desc: "test level 3"},
level: 3,
level: 3,
allowedOps: allowedOps{OpTypeSwap: true},
},
},
Expand All @@ -105,7 +105,7 @@ func TestCompositeHaltLevel_IsOperationAllowed(t *testing.T) {
{
name: "AND operator - should return false when any level denies",
composite: CompositeHaltLevel{
baseInfo: baseInfo{name: "composite and", desc: "test composite and"},
baseInfo: baseInfo{name: "composite and", desc: "test composite and"},
levels: HaltLevels{level1, level2},
operator: CompositeOpAnd,
},
Expand All @@ -115,7 +115,7 @@ func TestCompositeHaltLevel_IsOperationAllowed(t *testing.T) {
{
name: "OR operator - should return true when any level allows",
composite: CompositeHaltLevel{
baseInfo: baseInfo{name: "composite or", desc: "test composite or"},
baseInfo: baseInfo{name: "composite or", desc: "test composite or"},
levels: HaltLevels{level1, level2},
operator: CompositeOpOr,
},
Expand All @@ -125,7 +125,7 @@ func TestCompositeHaltLevel_IsOperationAllowed(t *testing.T) {
{
name: "OR operator - should return false when all levels deny",
composite: CompositeHaltLevel{
baseInfo: baseInfo{name: "composite or", desc: "test composite or"},
baseInfo: baseInfo{name: "composite or", desc: "test composite or"},
levels: HaltLevels{level1, level2},
operator: CompositeOpOr,
},
Expand Down
101 changes: 50 additions & 51 deletions contract/p/gnoswap/int256/cmp_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -262,56 +262,55 @@ func TestClone(t *testing.T) {
}
}


func TestNilChecks(t *testing.T) {
validInt := NewInt(123)

tests := []struct {
name string
fn func()
wantPanic string
}{
{
name: "Eq with nil",
fn: func() { validInt.Eq(nil) },
wantPanic: "int256: comparing with nil",
},
{
name: "Neq with nil",
fn: func() { validInt.Neq(nil) },
wantPanic: "int256: comparing with nil",
},
{
name: "Cmp with nil",
fn: func() { validInt.Cmp(nil) },
wantPanic: "int256: comparing with nil",
},
{
name: "Lt with nil",
fn: func() { validInt.Lt(nil) },
wantPanic: "int256: comparing with nil",
},
{
name: "Gt with nil",
fn: func() { validInt.Gt(nil) },
wantPanic: "int256: comparing with nil",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer func() {
r := recover()
if r == nil {
t.Errorf("%s: expected panic but got none", tt.name)
return
}
if r.(string) != tt.wantPanic {
t.Errorf("%s: got panic %v, want %v", tt.name, r, tt.wantPanic)
}
}()
tt.fn()
})
}
validInt := NewInt(123)

tests := []struct {
name string
fn func()
wantPanic string
}{
{
name: "Eq with nil",
fn: func() { validInt.Eq(nil) },
wantPanic: "int256: comparing with nil",
},
{
name: "Neq with nil",
fn: func() { validInt.Neq(nil) },
wantPanic: "int256: comparing with nil",
},
{
name: "Cmp with nil",
fn: func() { validInt.Cmp(nil) },
wantPanic: "int256: comparing with nil",
},
{
name: "Lt with nil",
fn: func() { validInt.Lt(nil) },
wantPanic: "int256: comparing with nil",
},
{
name: "Gt with nil",
fn: func() { validInt.Gt(nil) },
wantPanic: "int256: comparing with nil",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer func() {
r := recover()
if r == nil {
t.Errorf("%s: expected panic but got none", tt.name)
return
}
if r.(string) != tt.wantPanic {
t.Errorf("%s: got panic %v, want %v", tt.name, r, tt.wantPanic)
}
}()

tt.fn()
})
}
}
2 changes: 2 additions & 0 deletions contract/p/gnoswap/rbac/doc.gno
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@
// package main
//
// import (
//
// "std"
//
// "gno.land/p/gnoswap/rbac"
// "gno.land/p/demo/ufmt"
//
// )
//
// func main() {
Expand Down
2 changes: 1 addition & 1 deletion contract/p/gnoswap/rbac/role.gno
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type PermissionChecker func(caller std.Address) error
// Role represents a role information structure.
type Role struct {
// name represents the role's identifier
name string
name string
// permissions maps permission names to their respective checker functions
permissions map[string]PermissionChecker
}
Expand Down
20 changes: 10 additions & 10 deletions contract/p/gnoswap/uint256/bits_table.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ package uint256
//
// Example) 0x28 (binary 00101000)
//
// Binary: [ 0 0 1 0 1 0 0 0 ]
// ^^^^^^^^
// 3 consecutive zeros
// Binary: [ 0 0 1 0 1 0 0 0 ]
// ^^^^^^^^
// 3 consecutive zeros
//
// ntz8tab[0x28] = 3
// ntz8tab[0x28] = 3
const ntz8tab = "" +
"\x08\x00\x01\x00\x02\x00\x01\x00\x03\x00\x01\x00\x02\x00\x01\x00" +
"\x04\x00\x01\x00\x02\x00\x01\x00\x03\x00\x01\x00\x02\x00\x01\x00" +
Expand All @@ -36,10 +36,10 @@ const ntz8tab = "" +
//
// Example) 0xB2 (binary 10110010)
//
// Binary: [ 1 0 1 1 0 0 1 0 ]
// Total of 4 set bits
// Binary: [ 1 0 1 1 0 0 1 0 ]
// Total of 4 set bits
//
// pop8tab[0xB2] = 4
// pop8tab[0xB2] = 4
const pop8tab = "" +
"\x00\x01\x01\x02\x01\x02\x02\x03\x01\x02\x02\x03\x02\x03\x03\x04" +
"\x01\x02\x02\x03\x02\x03\x03\x04\x02\x03\x03\x04\x03\x04\x04\x05" +
Expand All @@ -63,10 +63,10 @@ const pop8tab = "" +
//
// Example) 0x16 (binary 00010110)
//
// Binary: [ 0 0 0 1 0 1 1 0 ]
// Reversed: [ 0 1 1 0 1 0 0 0 ] -> 0x68 (104 in decimal)
// Binary: [ 0 0 0 1 0 1 1 0 ]
// Reversed: [ 0 1 1 0 1 0 0 0 ] -> 0x68 (104 in decimal)
//
// rev8tab[0x16] = 0x68
// rev8tab[0x16] = 0x68
const rev8tab = "" +
"\x00\x80\x40\xc0\x20\xa0\x60\xe0\x10\x90\x50\xd0\x30\xb0\x70\xf0" +
"\x08\x88\x48\xc8\x28\xa8\x68\xe8\x18\x98\x58\xd8\x38\xb8\x78\xf8" +
Expand Down
6 changes: 3 additions & 3 deletions contract/r/gnoswap/common/util.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ func assertOnlyNotNil(value *u256.Uint) {

// getPrevRealm returns object of the previous realm.
func getPrevRealm() std.Realm {
return std.PrevRealm()
return std.PreviousRealm()
}

// getPrevAddr returns the address of the previous realm.
func getPrevAddr() std.Address {
return std.PrevRealm().Addr()
return std.PreviousRealm().Address()
}

// getPrevAsString returns the address and package path of the previous realm.
func getPrevAsString() (string, string) {
prev := getPrevRealm()
return prev.Addr().String(), prev.PkgPath()
return prev.Address().String(), prev.PkgPath()
}
6 changes: 3 additions & 3 deletions contract/r/gnoswap/community_pool/community_pool.gno
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func assertOnlyGovernance() {

// getPrevAddr returns the address of the caller.
func getPrevAddr() std.Address {
return std.PrevRealm().Addr()
return std.PreviousRealm().Address()
}

// getPrevAsString returns the address and realm of the caller as a string.
func getPrevAsString() (string, string) {
prev := std.PrevRealm()
return prev.Addr().String(), prev.PkgPath()
prev := std.PreviousRealm()
return prev.Address().String(), prev.PkgPath()
}
2 changes: 1 addition & 1 deletion contract/r/gnoswap/emission/emission.gno
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
func MintAndDistributeGns() uint64 {
assertOnlyNotHalted()

currentHeight := std.GetHeight()
currentHeight := std.ChainHeight()
lastMintedHeight := gns.GetLastMintedHeight()
if lastMintedHeight >= currentHeight {
// Skip if we've already minted tokens at this height
Expand Down
8 changes: 4 additions & 4 deletions contract/r/gnoswap/emission/utils.gno
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ const MAX_BPS_PCT uint64 = 10000

// getPrevRealm returns object of the previous realm.
func getPrevRealm() std.Realm {
return std.PrevRealm()
return std.PreviousRealm()
}

// getPrevAddr returns the address of the previous realm.
func getPrevAddr() std.Address {
return std.PrevRealm().Addr()
return std.PreviousRealm().Address()
}

// getPrev returns the address and package path of the previous realm.
func getPrevAsString() (string, string) {
prev := std.PrevRealm()
return prev.Addr().String(), prev.PkgPath()
prev := std.PreviousRealm()
return prev.Address().String(), prev.PkgPath()
}

// assertOnlyAdmin panics if the caller is not the admin.
Expand Down
6 changes: 3 additions & 3 deletions contract/r/gnoswap/gnft/utils.gno
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (

// getPrevAsString returns the address and package path of the previous realm.
func getPrevAsString() (string, string) {
prev := std.PrevRealm()
return prev.Addr().String(), prev.PkgPath()
prev := std.PreviousRealm()
return prev.Address().String(), prev.PkgPath()
}

// getPrevAddr returns the address of the previous realm.
func getPrevAddr() std.Address {
return std.PrevRealm().Addr()
return std.PreviousRealm().Address()
}

// tid converts uint64 to grc721.TokenID.
Expand Down
2 changes: 1 addition & 1 deletion contract/r/gnoswap/gns/_helper_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func resetObject(t *testing.T) {

resetGnsTokenObject(t)

height := std.GetHeight()
height := std.ChainHeight()
lastMintedHeight = height
}

Expand Down
6 changes: 3 additions & 3 deletions contract/r/gnoswap/gns/gns.gno
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func init() {
// leftEmissionAmount will decrease as tokens are minted.
setLeftEmissionAmount(MAX_EMISSION_AMOUNT)
setMintedEmissionAmount(uint64(0))
setLastMintedHeight(std.GetHeight())
setLastMintedHeight(std.ChainHeight())
burnAmount = uint64(0)
}

Expand Down Expand Up @@ -79,7 +79,7 @@ func Allowance(owner, spender std.Address) uint64 {

func MintGns(address std.Address) uint64 {
lastGNSMintedHeight := GetLastMintedHeight()
currentHeight := std.GetHeight()
currentHeight := std.ChainHeight()

// skip minting process if following conditions are met
// - if gns for current block is already minted
Expand Down Expand Up @@ -130,7 +130,7 @@ func Burn(from std.Address, amount uint64) {
"Burn",
"prevAddr", prevAddr,
"prevRealm", prevPkgPath,
"burnedBlockHeight", formatInt(std.GetHeight()),
"burnedBlockHeight", formatInt(std.ChainHeight()),
"burnFrom", from.String(),
"burnedGNSAmount", formatUint(amount),
"accumBurnedGNSAmount", formatUint(GetBurnAmount()),
Expand Down
Loading
Loading