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
22 changes: 0 additions & 22 deletions contract/r/gnoswap/launchpad/_mock_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,6 @@ func (m *MockLaunchpad) GetDepositAmount(depositId string) (int64, error) {
return res[0].(int64), res[1].(error)
}

func (m *MockLaunchpad) GetDepositWithdrawnHeight(depositId string) (int64, error) {
res, ok := m.Response.Get("GetDepositWithdrawnHeight")
if !ok {
return 0, nil
}
if len(res) < 2 || res[1] == nil {
return res[0].(int64), nil
}
return res[0].(int64), res[1].(error)
}

func (m *MockLaunchpad) GetDepositWithdrawnTime(depositId string) (int64, error) {
res, ok := m.Response.Get("GetDepositWithdrawnTime")
if !ok {
Expand All @@ -479,17 +468,6 @@ func (m *MockLaunchpad) GetDepositWithdrawnTime(depositId string) (int64, error)
return res[0].(int64), res[1].(error)
}

func (m *MockLaunchpad) GetDepositCreatedHeight(depositId string) (int64, error) {
res, ok := m.Response.Get("GetDepositCreatedHeight")
if !ok {
return 0, nil
}
if len(res) < 2 || res[1] == nil {
return res[0].(int64), nil
}
return res[0].(int64), res[1].(error)
}

func (m *MockLaunchpad) GetDepositCreatedAt(depositId string) (int64, error) {
res, ok := m.Response.Get("GetDepositCreatedAt")
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion contract/r/gnoswap/launchpad/counter_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math"
"testing"

uassert "gno.land/p/nt/uassert/v0"
"gno.land/p/nt/uassert/v0"
)

// Test for NewCounter, next, and Get methods.
Expand Down
75 changes: 25 additions & 50 deletions contract/r/gnoswap/launchpad/deposit.gno
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,19 @@ package launchpad
// - projectID (string): The ID of the project associated with the deposit.
// - tier (int64): The tier of the deposit.
// - depositAmount (int64): The amount of the deposit.
// - withdrawnHeight (int64): The height at which the deposit was withdrawn.
// - withdrawnTime (int64): The time when the deposit was withdrawn.
// - createdTime (int64): The time when the deposit was created.
// - createdAt (int64): The time when the deposit was created.
// - endTime (int64): The time when the deposit ends.
type Deposit struct {
depositor address

id string
projectID string
tier int64 // 30, 60, 180 // instead of tierId
depositAmount int64
withdrawnHeight int64
withdrawnTime int64
createdHeight int64
createdAt int64
endTime int64
id string
projectID string
tier int64 // 30, 60, 180 // instead of tierId
depositAmount int64
withdrawnTime int64
createdAt int64
endTime int64
}

func (d *Deposit) ID() string {
Expand Down Expand Up @@ -69,14 +66,6 @@ func (d *Deposit) SetDepositAmount(depositAmount int64) {
d.depositAmount = depositAmount
}

func (d *Deposit) CreatedHeight() int64 {
return d.createdHeight
}

func (d *Deposit) SetCreatedHeight(createdHeight int64) {
d.createdHeight = createdHeight
}

func (d *Deposit) CreatedAt() int64 {
return d.createdAt
}
Expand All @@ -93,14 +82,6 @@ func (d *Deposit) SetWithdrawnTime(withdrawnTime int64) {
d.withdrawnTime = withdrawnTime
}

func (d *Deposit) WithdrawnHeight() int64 {
return d.withdrawnHeight
}

func (d *Deposit) SetWithdrawnHeight(withdrawnHeight int64) {
d.withdrawnHeight = withdrawnHeight
}

func (d *Deposit) EndTime() int64 {
return d.endTime
}
Expand All @@ -122,26 +103,23 @@ func (d *Deposit) IsEnded(currentTime int64) bool {
}

func (d *Deposit) IsWithdrawn() bool {
return d.withdrawnTime > 0 && d.withdrawnHeight > 0
return d.withdrawnTime > 0
}

func (d *Deposit) SetWithdrawn(withdrawnHeight int64, withdrawnTime int64) {
d.withdrawnHeight = withdrawnHeight
func (d *Deposit) SetWithdrawn(withdrawnTime int64) {
d.withdrawnTime = withdrawnTime
}

func (d Deposit) Clone() *Deposit {
return &Deposit{
id: d.id,
projectID: d.projectID,
tier: d.tier,
depositor: d.depositor,
depositAmount: d.depositAmount,
withdrawnHeight: d.withdrawnHeight,
withdrawnTime: d.withdrawnTime,
createdHeight: d.createdHeight,
createdAt: d.createdAt,
endTime: d.endTime,
id: d.id,
projectID: d.projectID,
tier: d.tier,
depositor: d.depositor,
depositAmount: d.depositAmount,
withdrawnTime: d.withdrawnTime,
createdAt: d.createdAt,
endTime: d.endTime,
}
}

Expand All @@ -152,19 +130,16 @@ func NewDeposit(
tier int64,
depositor address,
depositAmount int64,
createdHeight int64,
createdTime int64,
endTime int64,
) *Deposit {
return &Deposit{
id: depositID,
projectID: projectID,
tier: tier,
depositor: depositor,
depositAmount: depositAmount,
withdrawnHeight: 0,
createdHeight: createdHeight,
createdAt: createdTime,
endTime: endTime,
id: depositID,
projectID: projectID,
tier: tier,
depositor: depositor,
depositAmount: depositAmount,
createdAt: createdTime,
endTime: endTime,
}
}
10 changes: 0 additions & 10 deletions contract/r/gnoswap/launchpad/getter.gno
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,11 @@ func GetDepositAmount(depositId string) (int64, error) {
return getImplementation().GetDepositAmount(depositId)
}

// GetDepositWithdrawnHeight returns the withdrawn height of a deposit by its ID.
func GetDepositWithdrawnHeight(depositId string) (int64, error) {
return getImplementation().GetDepositWithdrawnHeight(depositId)
}

// GetDepositWithdrawnTime returns the withdrawn time of a deposit by its ID.
func GetDepositWithdrawnTime(depositId string) (int64, error) {
return getImplementation().GetDepositWithdrawnTime(depositId)
}

// GetDepositCreatedHeight returns the created height of a deposit by its ID.
func GetDepositCreatedHeight(depositId string) (int64, error) {
return getImplementation().GetDepositCreatedHeight(depositId)
}

// GetDepositCreatedAt returns the created time of a deposit by its ID.
func GetDepositCreatedAt(depositId string) (int64, error) {
return getImplementation().GetDepositCreatedAt(depositId)
Expand Down
56 changes: 32 additions & 24 deletions contract/r/gnoswap/launchpad/getter_test.gno
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package launchpad

import (
avl "gno.land/p/nt/avl/v0"
u256 "gno.land/p/gnoswap/uint256"
uassert "gno.land/p/nt/uassert/v0"
"testing"

u256 "gno.land/p/gnoswap/uint256"
"gno.land/p/nt/avl/v0"
"gno.land/p/nt/uassert/v0"
)

func newLaunchpadDeposit() *Deposit {
deposit := NewDeposit("deposit-1", "project-1", 30, adminAddr, 1000, 10, 20, 30)
deposit.SetWithdrawnHeight(40)
deposit.SetWithdrawnTime(50)
deposit := NewDeposit("deposit-1", "project-1", 30, adminAddr, 1000, 20, 30)
deposit.SetWithdrawn(50)
return deposit
}

Expand Down Expand Up @@ -64,8 +64,8 @@ func TestMutableLaunchpadGetterIsolation(t *testing.T) {
assertRaw func(t *testing.T, m *MockLaunchpad)
}{
{
name: "GetProjectIDs",
setup: func(m *MockLaunchpad) { m.Response.Set("GetProjectIDs", []string{"project-1", "project-2"}) },
name: "GetProjectIDs",
setup: func(m *MockLaunchpad) { m.Response.Set("GetProjectIDs", []string{"project-1", "project-2"}) },
getter: func(t *testing.T) any { return GetProjectIDs(0, 10) },
mutate: func(result any) {
values := result.([]string)
Expand All @@ -79,7 +79,7 @@ func TestMutableLaunchpadGetterIsolation(t *testing.T) {
},
},
{
name: "GetProject",
name: "GetProject",
setup: func(m *MockLaunchpad) { m.Response.Set("GetProject", newLaunchpadProject(), nil) },
getter: func(t *testing.T) any {
value, err := GetProject("project-1")
Expand Down Expand Up @@ -112,7 +112,9 @@ func TestMutableLaunchpadGetterIsolation(t *testing.T) {
},
{
name: "GetProjectCondition",
setup: func(m *MockLaunchpad) { m.Response.Set("GetProjectCondition", NewProjectCondition("token-path", 500), nil) },
setup: func(m *MockLaunchpad) {
m.Response.Set("GetProjectCondition", NewProjectCondition("token-path", 500), nil)
},
getter: func(t *testing.T) any {
value, err := GetProjectCondition("project-1", "token-path")
uassert.NoError(t, err)
Expand Down Expand Up @@ -161,7 +163,7 @@ func TestMutableLaunchpadGetterIsolation(t *testing.T) {
},
},
{
name: "GetProjectTiersRatios",
name: "GetProjectTiersRatios",
setup: func(m *MockLaunchpad) { m.Response.Set("GetProjectTiersRatios", map[int64]int64{30: 25, 90: 75}, nil) },
getter: func(t *testing.T) any {
values, err := GetProjectTiersRatios("project-1")
Expand All @@ -182,7 +184,9 @@ func TestMutableLaunchpadGetterIsolation(t *testing.T) {
},
{
name: "GetProjectTierDistributeAmountPerSecondX128",
setup: func(m *MockLaunchpad) { m.Response.Set("GetProjectTierDistributeAmountPerSecondX128", u256.MustFromDecimal("100"), nil) },
setup: func(m *MockLaunchpad) {
m.Response.Set("GetProjectTierDistributeAmountPerSecondX128", u256.MustFromDecimal("100"), nil)
},
getter: func(t *testing.T) any {
value, err := GetProjectTierDistributeAmountPerSecondX128("project-1", 30)
uassert.NoError(t, err)
Expand All @@ -195,8 +199,8 @@ func TestMutableLaunchpadGetterIsolation(t *testing.T) {
},
},
{
name: "GetProjectTierDepositIDs",
setup: func(m *MockLaunchpad) { m.Response.Set("GetProjectTierDepositIDs", []string{"deposit-1", "deposit-2"}) },
name: "GetProjectTierDepositIDs",
setup: func(m *MockLaunchpad) { m.Response.Set("GetProjectTierDepositIDs", []string{"deposit-1", "deposit-2"}) },
getter: func(t *testing.T) any { return GetProjectTierDepositIDs("project-1", 30, 0, 10) },
mutate: func(result any) {
values := result.([]string)
Expand All @@ -210,7 +214,7 @@ func TestMutableLaunchpadGetterIsolation(t *testing.T) {
},
},
{
name: "GetDeposit",
name: "GetDeposit",
setup: func(m *MockLaunchpad) { m.Response.Set("GetDeposit", newLaunchpadDeposit(), nil) },
getter: func(t *testing.T) any {
value, err := GetDeposit("deposit-1")
Expand All @@ -223,10 +227,8 @@ func TestMutableLaunchpadGetterIsolation(t *testing.T) {
deposit.SetProjectID("mutated-project")
deposit.SetTier(90)
deposit.SetDepositAmount(2000)
deposit.SetCreatedHeight(99)
deposit.SetCreatedAt(88)
deposit.SetWithdrawnHeight(77)
deposit.SetWithdrawnTime(66)
deposit.SetWithdrawn(66)
deposit.SetEndTime(55)
},
assertRaw: func(t *testing.T, m *MockLaunchpad) {
Expand All @@ -235,16 +237,16 @@ func TestMutableLaunchpadGetterIsolation(t *testing.T) {
uassert.Equal(t, "project-1", deposit.ProjectID())
uassert.Equal(t, int64(30), deposit.Tier())
uassert.Equal(t, int64(1000), deposit.DepositAmount())
uassert.Equal(t, int64(10), deposit.CreatedHeight())
uassert.Equal(t, int64(20), deposit.CreatedAt())
uassert.Equal(t, int64(40), deposit.WithdrawnHeight())
uassert.Equal(t, int64(50), deposit.WithdrawnTime())
uassert.Equal(t, int64(30), deposit.EndTime())
},
},
{
name: "GetRewardState",
setup: func(m *MockLaunchpad) { m.Response.Set("GetRewardState", NewRewardState(u256.MustFromDecimal("700"), 800, 900, 1000, 1100), nil) },
setup: func(m *MockLaunchpad) {
m.Response.Set("GetRewardState", NewRewardState(u256.MustFromDecimal("700"), 800, 900, 1000, 1100), nil)
},
getter: func(t *testing.T) any {
value, err := GetRewardState("project-1:30", "deposit-1")
uassert.NoError(t, err)
Expand Down Expand Up @@ -275,7 +277,9 @@ func TestMutableLaunchpadGetterIsolation(t *testing.T) {
},
{
name: "GetProjectTierRewardManager",
setup: func(m *MockLaunchpad) { m.Response.Set("GetProjectTierRewardManager", newLaunchpadRewardManager(), nil) },
setup: func(m *MockLaunchpad) {
m.Response.Set("GetProjectTierRewardManager", newLaunchpadRewardManager(), nil)
},
getter: func(t *testing.T) any {
value, err := GetProjectTierRewardManager("project-1:30")
uassert.NoError(t, err)
Expand Down Expand Up @@ -326,7 +330,9 @@ func TestMutableLaunchpadGetterIsolation(t *testing.T) {
},
{
name: "GetProjectTierRewardDistributeAmountPerSecondX128",
setup: func(m *MockLaunchpad) { m.Response.Set("GetProjectTierRewardDistributeAmountPerSecondX128", u256.MustFromDecimal("300"), nil) },
setup: func(m *MockLaunchpad) {
m.Response.Set("GetProjectTierRewardDistributeAmountPerSecondX128", u256.MustFromDecimal("300"), nil)
},
getter: func(t *testing.T) any {
value, err := GetProjectTierRewardDistributeAmountPerSecondX128("project-1:30")
uassert.NoError(t, err)
Expand All @@ -340,7 +346,9 @@ func TestMutableLaunchpadGetterIsolation(t *testing.T) {
},
{
name: "GetProjectTierRewardAccumulatedRewardPerDepositX128",
setup: func(m *MockLaunchpad) { m.Response.Set("GetProjectTierRewardAccumulatedRewardPerDepositX128", u256.MustFromDecimal("500"), nil) },
setup: func(m *MockLaunchpad) {
m.Response.Set("GetProjectTierRewardAccumulatedRewardPerDepositX128", u256.MustFromDecimal("500"), nil)
},
getter: func(t *testing.T) any {
value, err := GetProjectTierRewardAccumulatedRewardPerDepositX128("project-1:30")
uassert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion contract/r/gnoswap/launchpad/project_condition_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package launchpad
import (
"testing"

uassert "gno.land/p/nt/uassert/v0"
"gno.land/p/nt/uassert/v0"
)

func TestProjectCondition_Getters(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions contract/r/gnoswap/launchpad/store_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"testing"

avl "gno.land/p/nt/avl/v0"
testutils "gno.land/p/nt/testutils/v0"
uassert "gno.land/p/nt/uassert/v0"
"gno.land/p/nt/testutils/v0"
"gno.land/p/nt/uassert/v0"
)

func TestStoreInitialization(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions contract/r/gnoswap/launchpad/types.gno
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ type ILaunchpadGetter interface {
GetDepositTier(depositId string) (int64, error)
GetDepositProjectTierID(depositId string) (string, error)
GetDepositAmount(depositId string) (int64, error)
GetDepositWithdrawnHeight(depositId string) (int64, error)
GetDepositWithdrawnTime(depositId string) (int64, error)
GetDepositCreatedHeight(depositId string) (int64, error)
GetDepositCreatedAt(depositId string) (int64, error)
GetDepositEndTime(depositId string) (int64, error)

Expand Down
2 changes: 0 additions & 2 deletions contract/r/gnoswap/launchpad/v1/assert_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ func TestAssert_assertIsDepositOwner(t *testing.T) {
30,
ownerAddr,
1000000,
100,
time.Now().Unix(),
time.Now().Unix()+1000,
)
Expand Down Expand Up @@ -128,7 +127,6 @@ func TestAssert_assertIsDepositOwner(t *testing.T) {
30,
ownerAddr,
1000000,
100,
time.Now().Unix(),
time.Now().Unix()+1000,
)
Expand Down
Loading
Loading