Skip to content

Commit

Permalink
feat: added Decimals field in the Metadata struct
Browse files Browse the repository at this point in the history
* Required to enable human readable formats in exchange module
  • Loading branch information
aarmoa authored and gorgos committed Jan 21, 2025
1 parent 3bd66ce commit d8651f9
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 62 deletions.
5 changes: 3 additions & 2 deletions tests/integration/bank/keeper/deterministic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ var (
Aliases: []string{"ATOM"},
},
},
Base: "uatom",
Display: "atom",
Base: "uatom",
Display: "atom",
Decimals: 6,
}
)

Expand Down
20 changes: 12 additions & 8 deletions x/bank/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,9 @@ func (suite *KeeperTestSuite) TestQueryDenomsMetadata() {
Aliases: []string{"ATOM"},
},
},
Base: "uatom",
Display: "atom",
Base: "uatom",
Display: "atom",
Decimals: 6,
}

metadataEth := types.Metadata{
Expand All @@ -425,8 +426,9 @@ func (suite *KeeperTestSuite) TestQueryDenomsMetadata() {
Aliases: []string{"ETH", "ether"},
},
},
Base: "wei",
Display: "eth",
Base: "wei",
Display: "eth",
Decimals: 18,
}

suite.bankKeeper.SetDenomMetaData(suite.ctx, metadataAtom)
Expand Down Expand Up @@ -507,8 +509,9 @@ func (suite *KeeperTestSuite) TestQueryDenomMetadata() {
Aliases: []string{"ATOM"},
},
},
Base: "uatom",
Display: "atom",
Base: "uatom",
Display: "atom",
Decimals: 6,
}

suite.bankKeeper.SetDenomMetaData(suite.ctx, expMetadata)
Expand Down Expand Up @@ -584,8 +587,9 @@ func (suite *KeeperTestSuite) TestQueryDenomMetadataByQueryStringRequest() {
Aliases: []string{"ATOM"},
},
},
Base: "uatom",
Display: "atom",
Base: "uatom",
Display: "atom",
Decimals: 6,
}

suite.bankKeeper.SetDenomMetaData(suite.ctx, expMetadata)
Expand Down
3 changes: 3 additions & 0 deletions x/bank/proto/cosmos/bank/v1beta1/bank.proto
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,7 @@ message Metadata {
// URIHash is a sha256 hash of a document pointed by URI. It's used to verify that
// the document didn't change. Optional.
string uri_hash = 8 [(gogoproto.customname) = "URIHash", (cosmos_proto.field_added_in) = "cosmos-sdk 0.46"];

// Decimals represent the number of decimals use to represent token amount on chain
uint32 decimals = 9 [(gogoproto.customname) = "Decimals", (cosmos_proto.field_added_in) = "cosmos-sdk 0.50-inj"];
}
130 changes: 84 additions & 46 deletions x/bank/types/bank.pb.go

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

15 changes: 9 additions & 6 deletions x/bank/types/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ func TestMetadataValidate(t *testing.T) {
{"matom", uint32(3), []string{"milliatom"}},
{"atom", uint32(6), nil},
},
Base: "uatom",
Display: "atom",
Base: "uatom",
Display: "atom",
Decimals: 6,
},
false,
},
Expand Down Expand Up @@ -148,8 +149,9 @@ func TestMetadataValidate(t *testing.T) {
{"matom", uint32(3), []string{"milliatom"}},
{"atom", uint32(6), nil},
},
Base: "uatom",
Display: "atom",
Base: "uatom",
Display: "atom",
Decimals: 6,
},
true,
},
Expand All @@ -164,8 +166,9 @@ func TestMetadataValidate(t *testing.T) {
{"matom", uint32(3), []string{"milliatom"}},
{"atom", uint32(6), nil},
},
Base: "uatom",
Display: "atom",
Base: "uatom",
Display: "atom",
Decimals: 6,
},
true,
},
Expand Down

0 comments on commit d8651f9

Please sign in to comment.