Skip to content

Commit

Permalink
chore(nodebuilder/state): SubmitTx endpoint takes read-level permissi…
Browse files Browse the repository at this point in the history
…ons (#3072)

<!--
Thank you for submitting a pull request!

Please make sure you have reviewed our contributors guide before
submitting your
first PR.

Please ensure you've addressed or included references to any related
issues.

Tips:
- Use keywords like "closes" or "fixes" followed by an issue number to
automatically close related issues when the PR is merged (e.g., "closes
#123" or "fixes #123").
- Describe the changes made in the PR.
- Ensure the PR has one of the required tags (kind:fix, kind:misc,
kind:break!, kind:refactor, kind:feat, kind:deps, kind:docs, kind:ci,
kind:chore, kind:testing)

-->
refactor: changes SubmitTX permissions from write to read.

Following the issue requirement, this PR changes SubmitTX permissions
from _write_ to _read_

Changes:

* Updated nodebuilder/state/state.go from **write** to **read**
permissions
* Updated following tests (api/rpc_test.go) and added extra check for
SubmitTX rpc call (read permissions check).

closes #2958

---------

Co-authored-by: [NODERS]TEAM <office@noders.team>
Co-authored-by: ramin <raminkeene@gmail.com>
  • Loading branch information
3 people authored and renaynay committed Jan 23, 2024
1 parent b7718a7 commit ed8a1b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions api/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,15 @@ func TestAuthedRPC(t *testing.T) {
// 2. Test method with write-level permissions
expectedResp := &state.TxResponse{}
if tt.perm > 2 {
server.State.EXPECT().SubmitTx(gomock.Any(), gomock.Any()).Return(expectedResp, nil)
txResp, err := rpcClient.State.SubmitTx(ctx, []byte{})
server.State.EXPECT().Delegate(gomock.Any(), gomock.Any(),
gomock.Any(), gomock.Any(), gomock.Any()).Return(expectedResp, nil)
txResp, err := rpcClient.State.Delegate(ctx,
state.ValAddress{}, state.Int{}, state.Int{}, 0)
require.NoError(t, err)
require.Equal(t, expectedResp, txResp)
} else {
_, err := rpcClient.State.SubmitTx(ctx, []byte{})
_, err := rpcClient.State.Delegate(ctx,
state.ValAddress{}, state.Int{}, state.Int{}, 0)
require.Error(t, err)
require.ErrorContains(t, err, "missing permission")
}
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type API struct {
fee state.Int,
gasLimit uint64,
) (*state.TxResponse, error) `perm:"write"`
SubmitTx func(ctx context.Context, tx state.Tx) (*state.TxResponse, error) `perm:"write"`
SubmitTx func(ctx context.Context, tx state.Tx) (*state.TxResponse, error) `perm:"read"`
SubmitPayForBlob func(
ctx context.Context,
fee state.Int,
Expand Down

0 comments on commit ed8a1b5

Please sign in to comment.