Skip to content

Commit

Permalink
client-sd/go: Add rofl.StakeThresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed Oct 24, 2024
1 parent 0ef2c7b commit 5fae8ee
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
22 changes: 18 additions & 4 deletions client-sdk/go/modules/rofl/rofl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ var (
methodRegister = types.NewMethodName("rofl.Register", Register{})

// Queries.
methodApp = types.NewMethodName("rofl.App", AppQuery{})
methodAppInstance = types.NewMethodName("rofl.AppInstance", AppInstanceQuery{})
methodAppInstances = types.NewMethodName("rofl.AppInstances", AppQuery{})
methodParameters = types.NewMethodName("rofl.Parameters", nil)
methodApp = types.NewMethodName("rofl.App", AppQuery{})
methodAppInstance = types.NewMethodName("rofl.AppInstance", AppInstanceQuery{})
methodAppInstances = types.NewMethodName("rofl.AppInstances", AppQuery{})
methodParameters = types.NewMethodName("rofl.Parameters", nil)
methodStakeThresholds = types.NewMethodName("rofl.StakeThresholds", nil)
)

// V1 is the v1 rofl module interface.
Expand All @@ -46,6 +47,9 @@ type V1 interface {
// AppInstances queries the registered instances of the given application.
AppInstances(ctx context.Context, round uint64, id AppID) ([]*Registration, error)

// StakeThresholds queries the stake information for managing ROFL.
StakeThresholds(ctx context.Context, round uint64) (*StakeThresholds, error)

// Parameters queries the module parameters.
Parameters(ctx context.Context, round uint64) (*Parameters, error)

Expand Down Expand Up @@ -110,6 +114,16 @@ func (a *v1) AppInstances(ctx context.Context, round uint64, id AppID) ([]*Regis
return instances, nil
}

// Implements V1.
func (a *v1) StakeThresholds(ctx context.Context, round uint64) (*StakeThresholds, error) {
var thresholds StakeThresholds
err := a.rc.Query(ctx, round, methodStakeThresholds, nil, &thresholds)
if err != nil {
return nil, err
}
return &thresholds, nil
}

// Implements V1.
func (a *v1) Parameters(ctx context.Context, round uint64) (*Parameters, error) {
var params Parameters
Expand Down
5 changes: 5 additions & 0 deletions client-sdk/go/modules/rofl/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,8 @@ type Event struct {
AppUpdated *AppUpdatedEvent
AppRemoved *AppRemovedEvent
}

// StakeThresholds contains staking thresholds for managing ROFL.
type StakeThresholds struct {
AppCreate *types.BaseUnits `json:"app_create"`
}
15 changes: 15 additions & 0 deletions tests/e2e/rofl/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"reflect"

"github.com/oasisprotocol/oasis-core/go/common/quantity"

"github.com/oasisprotocol/oasis-sdk/client-sdk/go/client"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/crypto/signature/ed25519"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/accounts"
Expand Down Expand Up @@ -105,6 +107,19 @@ func CreateUpdateRemoveTest(ctx context.Context, env *scenario.Env) error {
func QueryTest(ctx context.Context, env *scenario.Env) error {
rf := rofl.NewV1(env.Client)

// Query for stake thresholds.
s, err := rf.StakeThresholds(ctx, client.RoundLatest)
if err != nil {
return err
}
expected := types.BaseUnits{
Amount: *quantity.NewFromUint64(1_000),
Denomination: types.NativeDenomination,
}
if s.AppCreate.String() != expected.String() {
return fmt.Errorf("expected stake threshold app create '%s', got '%s'", expected, s.AppCreate)
}

// Derive the AppID for the example oracle ROFL application that is registered in genesis.
exampleAppID := rofl.NewAppIDGlobalName("example")

Expand Down

0 comments on commit 5fae8ee

Please sign in to comment.