Skip to content

Commit

Permalink
feat: value renderer for google.protobuf.Any (cosmos#13671)
Browse files Browse the repository at this point in the history
* chore: skeleton files for any renderer

* feat: first cut at Any renderer and tests

* test: Any fields, more tests, rename lookup by field

* docs: make Any example match the stated spec, and the implementation.

* refactor: use protojson for better test case legibility

* test: use protocmp for proto equality

See https://developers.google.com/protocol-buffers/docs/reference/go/faq#deepequal

* refactor: use json.RawMessage instead of remarshalling

* refactor: consistent pointer receiver for Textual
  • Loading branch information
JimLarson authored Nov 24, 2022
1 parent cfa224c commit 077abae
Show file tree
Hide file tree
Showing 15 changed files with 592 additions and 153 deletions.
23 changes: 12 additions & 11 deletions docs/architecture/adr-050-sign-mode-textual-annex1.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,18 @@ Object: <type_url>
#### Examples

```
Object: /cosmos.gov.v1.Vote
> Proposal id: 4
> Vote: cosmos1abc...def
> Options: 2 WeightedVoteOptions
> Options (1/2): WeightedVoteOption object
>> Option: Yes
>> Weight: 0.7
> Options (2/2): WeightedVoteOption object
>> Option: No
>> Weight: 0.3
> End of Options
Object: type.googleapis.com/cosmos.gov.v1.Vote
> Vote object
>> Proposal id: 4
>> Vote: cosmos1abc...def
>> Options: 2 WeightedVoteOptions
>> Options (1/2): WeightedVoteOption object
>>> Option: Yes
>>> Weight: 0.7
>> Options (2/2): WeightedVoteOption object
>>> Option: No
>>> Weight: 0.3
>> End of Options
```

### `google.protobuf.Timestamp`
Expand Down
76 changes: 76 additions & 0 deletions tx/textual/internal/testdata/any.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[
{
"proto": {
"@type": "type.googleapis.com/Foo"
},
"screens": [
{"text": "Object: type.googleapis.com/Foo"},
{"text": "Foo object", "indent": 1}
]
},
{
"proto": {
"@type": "type.googleapis.com/Foo",
"full_name": "testing"
},
"screens": [
{"text": "Object: type.googleapis.com/Foo"},
{"text": "Foo object", "indent": 1},
{"text": "Full name: testing", "indent": 2}
]
},
{
"proto": {
"@type": "type.googleapis.com/google.protobuf.Timestamp",
"value": "2006-01-02T15:04:05Z"
},
"screens": [
{"text": "Object: type.googleapis.com/google.protobuf.Timestamp"},
{"text": "2006-01-02T15:04:05Z", "indent": 1}
]
},
{
"proto": {
"@type": "type.googleapis.com/google.protobuf.Any",
"value": {
"@type": "type.googleapis.com/Foo"
}
},
"screens": [
{"text": "Object: type.googleapis.com/google.protobuf.Any"},
{"text": "Object: type.googleapis.com/Foo", "indent": 1},
{"text": "Foo object", "indent": 2}
]
},
{
"proto": {
"@type": "type.googleapis.com/google.protobuf.Any",
"value": {
"@type": "type.googleapis.com/Foo",
"full_name": "testing"
}
},
"screens": [
{"text": "Object: type.googleapis.com/google.protobuf.Any"},
{"text": "Object: type.googleapis.com/Foo", "indent": 1},
{"text": "Foo object", "indent": 2},
{"text": "Full name: testing", "indent": 3}
]
},
{
"proto": {
"@type": "type.googleapis.com/A",
"ANY": {
"@type": "type.googleapis.com/Foo",
"full_name": "testing"
}
},
"screens": [
{"text": "Object: type.googleapis.com/A"},
{"text": "A object", "indent": 1},
{"text": "ANY: Object: type.googleapis.com/Foo", "indent": 2},
{"text": "Foo object", "indent": 3},
{"text": "Full name: testing", "indent": 4}
]
}
]
9 changes: 6 additions & 3 deletions tx/textual/internal/testpb/1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";

option go_package = "cosmossdk.io/tx/textual/internal/testpb";

import "google/protobuf/any.proto";
import "google/protobuf/descriptor.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
Expand All @@ -23,6 +24,7 @@ message A {
google.protobuf.Timestamp TIMESTAMP = 10;
google.protobuf.Duration DURATION = 11;
ExternalEnum ENUM = 12;
google.protobuf.Any ANY = 13;

// Fields that are not handled by SIGN_MODE_TEXTUAL.
sint32 SINT32 = 101;
Expand All @@ -48,8 +50,9 @@ message Foo {

// Bar is a sample message type used for testing message rendering.
message Bar {
string bar_id = 1;
bytes data = 2;
string bar_id = 1;
bytes data = 2;
google.protobuf.Any payload = 3;
}

enum ExternalEnum {
Expand Down Expand Up @@ -77,4 +80,4 @@ enum BallotOption {
BALLOT_OPTION_ABSTAIN = 2;
BALLOT_OPTION_NO = 3;
BALLOT_OPTION_NO_WITH_VETO = 4;
}
}
Loading

0 comments on commit 077abae

Please sign in to comment.