-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Launchpad Architecture Refactoring (#451)
* chore: remove function prefix from panic msg * save * save * test: reward handler * feat: deposit handler * fix error * reward distributor * update test * update docs * fix * refactor deposit, launchpad, reward * reduce type size * fix rpc * refactor: error message * fix * fix * test: json builder * update deposit test * test: reward * fix * add launchpad new logic * catch compile errors * fix: weird interface nil error * refactor: reward empty * fix: when collecting deposit, check claimable Time (not ended height) * test: fix * test: fix MultipleDeposit * test: fix TestValidateRewardCollection - no such error * resolved some comments * remove unnecessary things * remove unnecessary json builder functuion * refactor: event message * update launchpad test * fix: reward_calculation * remove dummy_test file * additional refactor for `CreateProject` * fix: prevent throwing nil deref error in `CollectRewardByProjectId` * validate json creation * save * fix fee protocol * remove: token register * fix compile error for reward03 test * paritally fix: `CollectRewardByProjectId` -- update `RewardState` * fix * refactor: clean code and add comments for functions * test: reward calculation * update reward test * refactor: deposit refactoring * refactor: create project * refactor: deposit * refactor: reward by projectId * refactor: deposit and reward * refactor: left reward * refactor: reward test * refactor: move test code into test folder * refactor: remove unused code * chore: remove some comments * chore: remove comments * remove: hard-coded string * remove: invalid comments * fix: check duplicate collect gns --------- Co-authored-by: 0xTopaz <[email protected]> Co-authored-by: mconcat <[email protected]> Co-authored-by: n3wbie <[email protected]>
- Loading branch information
Showing
58 changed files
with
7,000 additions
and
2,285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package staker | ||
|
||
import ( | ||
"std" | ||
"testing" | ||
"time" | ||
|
||
"gno.land/p/demo/json" | ||
"gno.land/p/demo/testutils" | ||
"gno.land/p/demo/uassert" | ||
) | ||
|
||
func TestGetLockedInfoByAddress(t *testing.T) { | ||
addr := testutils.TestAddress("locked_info_test") | ||
|
||
now := uint64(time.Now().Unix()) | ||
lockedGNSList := []lockedGNS{ | ||
{amount: 1000, unlock: now - 100}, // already unlocked | ||
{amount: 2000, unlock: now + 100}, // still locked | ||
{amount: 3000, unlock: now - 50}, // already unlocked | ||
} | ||
addrLockedGns.Set(addr.String(), lockedGNSList) | ||
|
||
result := GetLockedInfoByAddress(addr) | ||
|
||
node := json.Must(json.Unmarshal([]byte(result))) | ||
|
||
uassert.True(t, node.HasKey("height")) | ||
uassert.True(t, node.HasKey("now")) | ||
uassert.True(t, node.HasKey("totalLocked")) | ||
uassert.True(t, node.HasKey("claimableAmount")) | ||
|
||
// summation of all the locked quantities | ||
totalLocked, err := node.MustKey("totalLocked").GetString() | ||
uassert.NoError(t, err) | ||
uassert.Equal(t, totalLocked, "6000") // 1000 + 2000 + 3000 = 6000 | ||
|
||
claimableAmount, err := node.MustKey("claimableAmount").GetString() | ||
uassert.NoError(t, err) | ||
uassert.Equal(t, claimableAmount, "4000") // 1000 + 3000 = 4000 | ||
} | ||
|
||
func TestGetLockedInfoByAddress_NoLocks(t *testing.T) { | ||
addr := testutils.TestAddress("no_locks_test") | ||
|
||
// no quantities are locked here | ||
result := GetLockedInfoByAddress(addr) | ||
uassert.Equal(t, result, "") | ||
} | ||
|
||
func TestGetLockedInfoByAddress_EmptyLocks(t *testing.T) { | ||
addr := testutils.TestAddress("empty_locks_test") | ||
|
||
addrLockedGns.Set(addr.String(), []lockedGNS{}) | ||
|
||
result := GetLockedInfoByAddress(addr) | ||
|
||
node := json.Must(json.Unmarshal([]byte(result))) | ||
uassert.True(t, node.HasKey("height")) | ||
uassert.True(t, node.HasKey("now")) | ||
uassert.True(t, node.HasKey("totalLocked")) | ||
uassert.True(t, node.HasKey("claimableAmount")) | ||
|
||
totalLocked, err := node.MustKey("totalLocked").GetString() | ||
uassert.NoError(t, err) | ||
uassert.Equal(t, totalLocked, "0") | ||
|
||
claimableAmount, err := node.MustKey("claimableAmount").GetString() | ||
uassert.NoError(t, err) | ||
uassert.Equal(t, claimableAmount, "0") | ||
} | ||
|
||
func TestGetClaimableRewardByAddress(t *testing.T) { | ||
addr := testutils.TestAddress("claimable_test") | ||
|
||
rewardState.AddStake(uint64(std.GetHeight()), addr, 100, 0, nil) | ||
|
||
currentGNSBalance = 1000 | ||
// userEmissionReward.Set(addr.String(), uint64(1000)) | ||
|
||
currentProtocolFeeBalance["token1:token2"] = 500 | ||
currentProtocolFeeBalance["token2:token3"] = 300 | ||
//pfTree := avl.NewTree() | ||
//pfTree.Set("token1:token2", uint64(500)) | ||
//pfTree.Set("token2:token3", uint64(300)) | ||
//userProtocolFeeReward.Set(addr.String(), pfTree) | ||
|
||
result := GetClaimableRewardByAddress(addr) | ||
|
||
node := json.Must(json.Unmarshal([]byte(result))) | ||
|
||
uassert.True(t, node.HasKey("height")) | ||
uassert.True(t, node.HasKey("now")) | ||
|
||
emissionReward, err := node.MustKey("emissionReward").GetString() | ||
uassert.NoError(t, err) | ||
uassert.Equal(t, emissionReward, "1000") | ||
|
||
protocolFees := node.MustKey("protocolFees") | ||
uassert.True(t, protocolFees.IsArray()) | ||
|
||
protocolFees.ArrayEach(func(i int, fee *json.Node) { | ||
tokenPath, err := fee.MustKey("tokenPath").GetString() | ||
uassert.NoError(t, err) | ||
|
||
amount, err := fee.MustKey("amount").GetString() | ||
uassert.NoError(t, err) | ||
|
||
switch tokenPath { | ||
case "token1:token2": | ||
uassert.Equal(t, amount, "500") | ||
case "token2:token3": | ||
uassert.Equal(t, amount, "300") | ||
default: | ||
t.Errorf("unexpected tokenPath: %s", tokenPath) | ||
} | ||
}) | ||
} | ||
|
||
func TestGetClaimableRewardByAddress_NoRewards(t *testing.T) { | ||
addr := testutils.TestAddress("no_reward_test") | ||
|
||
result := GetClaimableRewardByAddress(addr) | ||
uassert.Equal(t, result, "") | ||
} |
Oops, something went wrong.