Skip to content

Commit

Permalink
Merge branch 'refactor/non-custodial-staking-tests' into refactor/sup…
Browse files Browse the repository at this point in the history
…plier-operator-renaming
  • Loading branch information
red-0ne committed Aug 13, 2024
2 parents 73decdb + e52e1d9 commit 19c0e7a
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 37 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ check_ignite_version:
exit 1 ; \
fi

.PHONY: check_mockgen
# Internal helper target- Check if mockgen is installed
check_mockgen:
{ \
if ( ! ( command -v mockgen >/dev/null )); then \
echo "Seems like you don't have `mockgen` installed. Please visit https://github.com/golang/mock#installation and follow the instructions to install `mockgen` before continuing"; \
exit 1; \
fi; \
}


.PHONY: check_act
# Internal helper target - check if `act` is installed
check_act:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ You can view the Shannon Roadmap on [Github](https://github.com/orgs/pokt-networ

## Quickstart

The best way to get involved is by following the [quickstart instructions](<[./develop/developer_guide/quickstart.md](https://dev.poktroll.com/develop/developer_guide/quickstart)>).
The best way to get involved is by following the [quickstart instructions](https://dev.poktroll.com/develop/developer_guide/quickstart).

## Godoc

Expand Down
4 changes: 2 additions & 2 deletions api/poktroll/shared/supplier.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions docusaurus/docs/develop/developer_guide/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ available commands. Looking inside the Makefile is a great way to learn how to u

### 1.3 Prepare your development environment

Run the following command to install `golang` dependencies:
```bash
make install_ci_deps
```

If you encounter issues related to `mockgen` not being found or failing, try running the following command to verify its installation:
```bash
make check_mockgen
```

Compile protobufs, generate mocks and verify that all tests are passing by running:

```bash
Expand Down
4 changes: 2 additions & 2 deletions proto/poktroll/shared/supplier.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ message Supplier {
string owner_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // Bech32 cosmos address
// The operator address of the supplier operator (i.e. the one managing the off-chain server).
// The operator address can update the supplier's configurations excluding the owner address.
// This property do not change over the supplier's lifespan, the supplier must be usnaked
// and staked again to update this value.
// This property does not change over the supplier's lifespan, the supplier must be unstaked
// and re-staked to effectively update this value.
string operator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // Bech32 cosmos address
cosmos.base.v1beta1.Coin stake = 3; // The total amount of uPOKT the supplier has staked
repeated SupplierServiceConfig services = 4; // The service configs this supplier can support
Expand Down
4 changes: 2 additions & 2 deletions x/shared/types/supplier.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions x/supplier/config/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
)

var (
ErrSupplierConfigUnmarshalYAML = sdkerrors.Register(types.ModuleName, 2100, "config reader cannot unmarshal yaml content")
ErrSupplierConfigInvalidServiceId = sdkerrors.Register(types.ModuleName, 2101, "invalid serviceId in supplier config")
ErrSupplierConfigNoEndpoints = sdkerrors.Register(types.ModuleName, 2102, "no endpoints defined for serviceId in supplier config")
ErrSupplierConfigInvalidEndpointConfig = sdkerrors.Register(types.ModuleName, 2103, "invalid endpoint config in supplier config")
ErrSupplierConfigInvalidRPCType = sdkerrors.Register(types.ModuleName, 2104, "invalid rpc type in supplier config")
ErrSupplierConfigInvalidURL = sdkerrors.Register(types.ModuleName, 2105, "invalid endpoint url in supplier config")
ErrSupplierConfigEmptyContent = sdkerrors.Register(types.ModuleName, 2106, "empty supplier config content")
ErrSupplierConfigInvalidStake = sdkerrors.Register(types.ModuleName, 2107, "invalid stake amount in supplier config")
ErrSupplierConfigInvalidAddress = sdkerrors.Register(types.ModuleName, 2108, "missing owner address in supplier config")
ErrSupplierConfigUnmarshalYAML = sdkerrors.Register(types.ModuleName, 2100, "config reader cannot unmarshal yaml content")
ErrSupplierConfigInvalidServiceId = sdkerrors.Register(types.ModuleName, 2101, "invalid serviceId in supplier config")
ErrSupplierConfigNoEndpoints = sdkerrors.Register(types.ModuleName, 2102, "no endpoints defined for serviceId in supplier config")
ErrSupplierConfigInvalidEndpointConfig = sdkerrors.Register(types.ModuleName, 2103, "invalid endpoint config in supplier config")
ErrSupplierConfigInvalidRPCType = sdkerrors.Register(types.ModuleName, 2104, "invalid rpc type in supplier config")
ErrSupplierConfigInvalidURL = sdkerrors.Register(types.ModuleName, 2105, "invalid endpoint url in supplier config")
ErrSupplierConfigEmptyContent = sdkerrors.Register(types.ModuleName, 2106, "empty supplier config content")
ErrSupplierConfigInvalidStake = sdkerrors.Register(types.ModuleName, 2107, "invalid stake amount in supplier config")
ErrSupplierConfigInvalidOwnerAddress = sdkerrors.Register(types.ModuleName, 2108, "invalid owner address in supplier config")
ErrSupplierConfigInvalidOperatorAddress = sdkerrors.Register(types.ModuleName, 2109, "invalid operator address in supplier config")
)
18 changes: 2 additions & 16 deletions x/supplier/config/supplier_configs_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
_ "github.com/pokt-network/poktroll/pkg/polylog/polyzero"
sharedhelpers "github.com/pokt-network/poktroll/x/shared/helpers"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
"github.com/pokt-network/poktroll/x/supplier/types"
)

// YAMLStakeConfig is the structure describing the supplier stake config file.
Expand Down Expand Up @@ -46,19 +45,6 @@ type SupplierStakeConfig struct {
Services []*sharedtypes.SupplierServiceConfig
}

// EnsureOwner ensures that the config owner address matches the provided address.
func (cfg *SupplierStakeConfig) EnsureOwner(ownerAddress string) error {
if cfg.OwnerAddress != ownerAddress {
return types.ErrSupplierInvalidAddress.Wrapf(
"owner address %q in the stake config file does not match the address provided %q",
cfg.OperatorAddress,
ownerAddress,
)
}

return nil
}

// ParseSupplierServiceConfig parses the stake config file into a SupplierServiceConfig.
func ParseSupplierConfigs(ctx context.Context, configContent []byte) (*SupplierStakeConfig, error) {
var stakeConfig *YAMLStakeConfig
Expand All @@ -76,7 +62,7 @@ func ParseSupplierConfigs(ctx context.Context, configContent []byte) (*SupplierS

// Validate required owner address.
if _, err := sdk.AccAddressFromBech32(stakeConfig.OwnerAddress); err != nil {
return nil, ErrSupplierConfigInvalidAddress.Wrap("invalid owner address")
return nil, ErrSupplierConfigInvalidOwnerAddress.Wrap("invalid owner address")
}

// If the operator address is not set, default it to the owner address.
Expand All @@ -87,7 +73,7 @@ func ParseSupplierConfigs(ctx context.Context, configContent []byte) (*SupplierS

// Validate operator address.
if _, err := sdk.AccAddressFromBech32(stakeConfig.OperatorAddress); err != nil {
return nil, ErrSupplierConfigInvalidAddress.Wrap("invalid operator address")
return nil, ErrSupplierConfigInvalidOperatorAddress.Wrap("invalid operator address")
}

// Validate the stake amount
Expand Down
6 changes: 3 additions & 3 deletions x/supplier/config/supplier_configs_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) {
config:
timeout: 10
`, operatorAddress),
expectedError: config.ErrSupplierConfigInvalidAddress,
expectedError: config.ErrSupplierConfigInvalidOwnerAddress,
},
{
desc: "invalid owner address",
Expand All @@ -517,7 +517,7 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) {
config:
timeout: 10
`, operatorAddress),
expectedError: config.ErrSupplierConfigInvalidAddress,
expectedError: config.ErrSupplierConfigInvalidOwnerAddress,
},
{
desc: "invalid operator address",
Expand All @@ -533,7 +533,7 @@ func Test_ParseSupplierConfigs_Services(t *testing.T) {
config:
timeout: 10
`, ownerAddress),
expectedError: config.ErrSupplierConfigInvalidAddress,
expectedError: config.ErrSupplierConfigInvalidOperatorAddress,
},
}

Expand Down
2 changes: 1 addition & 1 deletion x/supplier/keeper/msg_server_stake_supplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (k msgServer) StakeSupplier(ctx context.Context, msg *types.MsgStakeSupplie
logger.Error("updating the supplier's operator address forbidden")

return nil, sharedtypes.ErrSharedUnauthorizedSupplierUpdate.Wrap(
"updating the operator address is forbidden, unstake then stake again in order to change the operator address",
"updating the operator address is forbidden, unstake then re-stake with the updated operator address",
)
}

Expand Down
3 changes: 2 additions & 1 deletion x/supplier/keeper/msg_server_stake_supplier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func TestMsgServer_StakeSupplier_OperatorAuthorizations(t *testing.T) {
require.True(t, supplierFound)
require.Equal(t, operatorUpdatedServiceUrl, foundSupplier.Services[0].Endpoints[0].Url)

// Update the supplier using the owner address as the singer and verify that it succeeds.
// Update the supplier URL by using the owner address as the singer and verify that it succeeds.
ownerUpdaterServiceUrl := "http://localhost:8082"
stakeMsgUpdateUrl.Services[0].Endpoints[0].Url = ownerUpdaterServiceUrl
stakeMsgUpdateUrl.Stake.Amount = math.NewInt(300)
Expand All @@ -203,6 +203,7 @@ func TestMsgServer_StakeSupplier_OperatorAuthorizations(t *testing.T) {
foundSupplier, supplierFound = k.GetSupplier(ctx, operatorAddr)
require.True(t, supplierFound)
require.Equal(t, ownerUpdaterServiceUrl, foundSupplier.Services[0].Endpoints[0].Url)
require.NotEqual(t, operatorUpdatedServiceUrl, foundSupplier.Services[0].Endpoints[0].Url)

// Try updating the supplier's operator address using the old operator as a signer
// will create a new supplier.
Expand Down

0 comments on commit 19c0e7a

Please sign in to comment.