-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(oracle): update params #83
Merged
leonz789
merged 17 commits into
ExocoreNetwork:develop
from
leonz789:develop-oracle-updateparams
Jul 17, 2024
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
81e0ef3
feat(oracle): add service for params udpate
leonz789 d1ffd59
ref(oracle)
leonz789 3f76f0b
feat(oracle):add params validation method
leonz789 62529fd
test(oracle): add test for updateparams
leonz789 d1ac7e2
add comments for params.go, udpate validation for AddToken
leonz789 3dbec4b
typo
leonz789 ebbd424
Merge branch 'develop' into develop-oracle-updateparams
cloud8little 4f1acf2
lint
leonz789 ce11543
feat(oracle):add cli to support oracle updateParams for test
leonz789 bf6d912
Merge branch 'develop' into develop-oracle-updateparams
leonz789 834861a
Update errors.go
cloud8little 1e32628
typo
leonz789 02529bd
add error logs for updateParams
leonz789 857a1be
test:add some new test cases
leonz789 4ed528f
test: add some positive cases for update params
leonz789 e1b1e5b
Merge branch 'develop' into develop-oracle-updateparams
leonz789 e9eb65b
add TODO for future performance improvement
leonz789 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,33 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/ExocoreNetwork/exocore/x/oracle/types" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func CmdUpdateParams() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
// TODO: support v1 single sourceID for temporary | ||
Use: "update-params params", | ||
Short: "Broadcast message update-params", | ||
Args: cobra.MinimumNArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
msg := types.NewMsgUpdateParams(clientCtx.GetFromAddress().String(), args[0]) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
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,155 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"github.com/ExocoreNetwork/exocore/x/oracle/types" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("MsgUpdateParams", func() { | ||
var defaultParams types.Params | ||
BeforeEach(func() { | ||
ks.Reset() | ||
Expect(ks.ms).ToNot(BeNil()) | ||
defaultParams = ks.k.GetParams(ks.ctx) | ||
}) | ||
|
||
Context("Update Chains", func() { | ||
inputAddChains := []string{ | ||
`{"chains":[{"name":"Bitcoin", "desc":"-"}]}`, | ||
`{"chains":[{"name":"Ethereum", "desc":"-"}]}`, | ||
} | ||
It("add chain with new name", func() { | ||
msg := types.NewMsgUpdateParams("", inputAddChains[0]) | ||
_, err := ks.ms.UpdateParams(ks.ctx, msg) | ||
Expect(err).Should(BeNil()) | ||
p := ks.k.GetParams(ks.ctx) | ||
Expect(p.Chains[2].Name).Should(BeEquivalentTo("Bitcoin")) | ||
|
||
}) | ||
It("add chain with duplicated name", func() { | ||
_, err := ks.ms.UpdateParams(ks.ctx, types.NewMsgUpdateParams("", inputAddChains[1])) | ||
Expect(err).Should(MatchError(types.ErrInvalidParams.Wrap("invalid source to add, duplicated"))) | ||
}) | ||
}) | ||
Context("Update Sources", func() { | ||
inputAddSources := []string{ | ||
`{"sources":[{"name":"CoinGecko", "desc":"-", "valid":true}]}`, | ||
`{"sources":[{"name":"CoinGecko", "desc":"-"}]}`, | ||
`{"sources":[{"name":"Chainlink", "desc":"-", "valid":true}]}`, | ||
} | ||
It("add valid source with new name", func() { | ||
_, err := ks.ms.UpdateParams(ks.ctx, types.NewMsgUpdateParams("", inputAddSources[0])) | ||
Expect(err).Should(BeNil()) | ||
p := ks.k.GetParams(ks.ctx) | ||
Expect(p.Sources[2].Name).Should(BeEquivalentTo("CoinGecko")) | ||
}) | ||
It("add invalid source with new name", func() { | ||
_, err := ks.ms.UpdateParams(ks.ctx, types.NewMsgUpdateParams("", inputAddSources[1])) | ||
Expect(err).Should(MatchError(types.ErrInvalidParams.Wrap("invalid source to add, new source should be valid"))) | ||
}) | ||
It("add source with duplicated name", func() { | ||
_, err := ks.ms.UpdateParams(ks.ctx, types.NewMsgUpdateParams("", inputAddSources[2])) | ||
Expect(err).Should(MatchError(types.ErrInvalidParams.Wrap("invalid source to add, duplicated"))) | ||
}) | ||
}) | ||
Context("Update Tokens", func() { | ||
startBasedBlocks := []uint64{1, 3, 3, 3, 1, 1, 1} | ||
inputUpdateTokens := []string{ | ||
`{"tokens":[{"name":"UNI", "chain_id":"1"}]}`, | ||
`{"tokens":[{"name":"ETH", "chain_id":"1", "decimal":8}]}`, | ||
`{"tokens":[{"name":"ETH", "chain_id":"1", "asset_id":"assetID"}]}`, | ||
`{"tokens":[{"name":"ETH", "chain_id":"1", "contract_address":"contractAddress"}]}`, | ||
`{"tokens":[{"name":"ETH", "chain_id":"1", "decimal":8}]}`, | ||
`{"tokens":[{"name":"ETH", "chain_id":"0"}]}`, | ||
`{"tokens":[{"name":"ETH", "chain_id":"3"}]}`, | ||
} | ||
errs := []error{ | ||
nil, | ||
nil, | ||
nil, | ||
nil, | ||
nil, | ||
types.ErrInvalidParams.Wrap("invalid token to add, chain not found"), | ||
types.ErrInvalidParams.Wrap("invalid token to add, chain not found"), | ||
} | ||
token := types.DefaultParams().Tokens[1] | ||
token1 := *token | ||
token1.Decimal = 8 | ||
|
||
token2 := *token | ||
token2.AssetID = "assetID" | ||
|
||
token3 := *token | ||
token3.ContractAddress = "0x123" | ||
|
||
updatedTokenETH := []*types.Token{ | ||
nil, | ||
&token1, | ||
&token2, | ||
&token3, | ||
token, | ||
nil, | ||
nil, | ||
} | ||
|
||
for i, input := range inputUpdateTokens { | ||
It("", func() { //}) | ||
if startBasedBlocks[i] > 1 { | ||
p := defaultParams | ||
p.TokenFeeders[1].StartBaseBlock = startBasedBlocks[i] | ||
ks.k.SetParams(ks.ctx, p) | ||
} | ||
_, err := ks.ms.UpdateParams(ks.ctx, types.NewMsgUpdateParams("", input)) | ||
if errs[i] == nil { | ||
Expect(err).Should(BeNil()) | ||
} else { | ||
Expect(err).Should(MatchError(errs[i])) | ||
} | ||
if updatedTokenETH[i] != nil { | ||
p := ks.k.GetParams(ks.ctx) | ||
Expect(p.Tokens[1]).Should(BeEquivalentTo(updatedTokenETH[i])) | ||
} | ||
}) | ||
} | ||
|
||
}) | ||
|
||
Context("", func() { | ||
It("update StartBaseBlock for TokenFeeder", func() { | ||
p := defaultParams | ||
p.TokenFeeders[1].StartBaseBlock = 10 | ||
ks.k.SetParams(ks.ctx, p) | ||
p.TokenFeeders[1].StartBaseBlock = 5 | ||
_, err := ks.ms.UpdateParams(ks.ctx, &types.MsgUpdateParams{ | ||
Params: types.Params{ | ||
TokenFeeders: []*types.TokenFeeder{ | ||
{ | ||
TokenID: 1, | ||
StartBaseBlock: 5, | ||
}, | ||
}, | ||
}, | ||
}) | ||
Expect(err).Should(BeNil()) | ||
p = ks.k.GetParams(ks.ctx) | ||
Expect(p.TokenFeeders[1].StartBaseBlock).Should(BeEquivalentTo(5)) | ||
}) | ||
It("Add AssetID for Token", func() { | ||
_, err := ks.ms.UpdateParams(ks.ctx, &types.MsgUpdateParams{ | ||
Params: types.Params{ | ||
Tokens: []*types.Token{ | ||
{ | ||
Name: "ETH", | ||
ChainID: 1, | ||
AssetID: "0x83e6850591425e3c1e263c054f4466838b9bd9e4_0x9ce1", | ||
}, | ||
}, | ||
}, | ||
}) | ||
Expect(err).Should(BeNil()) | ||
p := ks.k.GetParams(ks.ctx) | ||
Expect(p.Tokens[1].AssetID).Should(BeEquivalentTo("0x83e6850591425e3c1e263c054f4466838b9bd9e4_0x9ce1")) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
Consider security implications of the commented-out authority check.
The authority check is still commented out in the file
x/oracle/keeper/msg_server_update_params.go
. It's crucial to ensure this is re-enabled in production to prevent unauthorized updates to parameters.x/oracle/keeper/msg_server_update_params.go
Analysis chain
Consider security implications of the commented-out authority check.
The authority check is commented out with a TODO note for testing purposes. It's crucial to ensure this is re-enabled in production to prevent unauthorized updates to parameters.
Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 471
Script:
Length of output: 129