-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tokenomics] SettleSessionAccounting first implementation (emissions=…
…burn) (#323) Implement `SettleSessionAccounting` where emissions=burn. - Issue: #243 --- Co-authored-by: Redouane Lakrache <[email protected]> Co-authored-by: Dima Kniazev <[email protected]> Co-authored-by: Bryan White <[email protected]>
- Loading branch information
1 parent
254225d
commit 66e3320
Showing
23 changed files
with
674 additions
and
55 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
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,13 @@ | ||
Feature: Tokenomics Namespaces | ||
|
||
# This test | ||
Scenario: Basic tokenomics validation that Supplier mint equals Application burn | ||
Given the user has the pocketd binary installed | ||
And an account exists for "supplier1" | ||
And an account exists for "app1" | ||
When the supplier "supplier1" has serviced a session with "20" relays for service "svc1" for application "app1" | ||
And the user should wait for "5" seconds | ||
# TODO_UPNEXT(@Olshansk, #359): Expand on the two expectations below after integrating the tokenomics module | ||
# into the supplier module. | ||
# Then the account balance of "supplier1" should be "1000" uPOKT "more" than before | ||
# And the account balance of "app1" should be "1000" uPOKT "less" than before |
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
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,34 @@ | ||
package types | ||
|
||
import ( | ||
sdkerrors "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// TODO_TECHDEBT: Make sure this is used everywhere we validate components | ||
// of the session header. | ||
func (sh *SessionHeader) ValidateBasic() error { | ||
// Validate the application address | ||
if _, err := sdk.AccAddressFromBech32(sh.ApplicationAddress); err != nil { | ||
return sdkerrors.Wrapf(ErrSessionInvalidAppAddress, "invalid application address: %s; (%v)", sh.ApplicationAddress, err) | ||
} | ||
|
||
// Validate the session ID | ||
// TODO_TECHDEBT: Introduce a `SessionId#ValidateBasic` method. | ||
if sh.SessionId == "" { | ||
return sdkerrors.Wrapf(ErrSessionInvalidSessionId, "invalid session ID: %s", sh.SessionId) | ||
} | ||
|
||
// Validate the service | ||
// TODO_TECHDEBT: Introduce a `Service#ValidateBasic` method. | ||
if sh.Service == nil { | ||
return sdkerrors.Wrapf(ErrSessionInvalidService, "invalid service: %s", sh.Service) | ||
} | ||
|
||
// Check if session end height is greater than session start height | ||
if sh.SessionEndBlockHeight <= sh.SessionStartBlockHeight { | ||
return sdkerrors.Wrapf(ErrSessionInvalidBlockHeight, "session end block height cannot be less than or equal to session start block height") | ||
} | ||
|
||
return nil | ||
} |
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,86 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/pokt-network/poktroll/testutil/sample" | ||
"github.com/pokt-network/poktroll/x/session/types" | ||
sharedtypes "github.com/pokt-network/poktroll/x/shared/types" | ||
) | ||
|
||
func TestSessionHeader_ValidateBasic(t *testing.T) { | ||
tests := []struct { | ||
desc string | ||
sh types.SessionHeader | ||
err error | ||
}{ | ||
{ | ||
desc: "invalid - invalid application address", | ||
sh: types.SessionHeader{ | ||
ApplicationAddress: "invalid_address", | ||
SessionId: "valid_session_id", | ||
Service: &sharedtypes.Service{}, | ||
SessionStartBlockHeight: 100, | ||
SessionEndBlockHeight: 101, | ||
}, | ||
err: types.ErrSessionInvalidAppAddress, | ||
}, | ||
{ | ||
desc: "invalid - empty session id", | ||
sh: types.SessionHeader{ | ||
ApplicationAddress: sample.AccAddress(), | ||
SessionId: "", | ||
Service: &sharedtypes.Service{}, | ||
SessionStartBlockHeight: 100, | ||
SessionEndBlockHeight: 101, | ||
}, | ||
err: types.ErrSessionInvalidSessionId, | ||
}, | ||
{ | ||
desc: "invalid - nil service", | ||
sh: types.SessionHeader{ | ||
ApplicationAddress: sample.AccAddress(), | ||
SessionId: "valid_session_id", | ||
Service: nil, | ||
SessionStartBlockHeight: 100, | ||
SessionEndBlockHeight: 101, | ||
}, | ||
err: types.ErrSessionInvalidService, | ||
}, | ||
{ | ||
desc: "invalid - start block height greater than end block height", | ||
sh: types.SessionHeader{ | ||
ApplicationAddress: sample.AccAddress(), | ||
SessionId: "valid_session_id", | ||
Service: &sharedtypes.Service{}, | ||
SessionStartBlockHeight: 100, | ||
SessionEndBlockHeight: 99, | ||
}, | ||
err: types.ErrSessionInvalidBlockHeight, | ||
}, | ||
{ | ||
desc: "valid", | ||
sh: types.SessionHeader{ | ||
ApplicationAddress: sample.AccAddress(), | ||
SessionId: "valid_session_id", | ||
Service: &sharedtypes.Service{}, | ||
SessionStartBlockHeight: 100, | ||
SessionEndBlockHeight: 101, | ||
}, | ||
err: nil, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.desc, func(t *testing.T) { | ||
err := tt.sh.ValidateBasic() | ||
if tt.err != nil { | ||
require.ErrorIs(t, err, tt.err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.