Skip to content
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

[FAB-18508] ledger utility always outputs txNum #2724

Merged
merged 1 commit into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions internal/ledger/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,14 @@ func Compare(snapshotDir1 string, snapshotDir2 string, outputFile string) (count
type diffRecord struct {
Namespace string `json:"namespace,omitempty"`
Key string `json:"key,omitempty"`
Record1 *snapshotRecord `json:"snapshotrecord1,omitempty"`
Record2 *snapshotRecord `json:"snapshotrecord2,omitempty"`
Record1 *snapshotRecord `json:"snapshotrecord1"`
Record2 *snapshotRecord `json:"snapshotrecord2"`
}

// Creates a new diffRecord
func newDiffRecord(namespace string, record1 *privacyenabledstate.SnapshotRecord,
record2 *privacyenabledstate.SnapshotRecord) (*diffRecord, error) {
// Empty snapshot
s0 := snapshotRecord{
Value: "",
BlockNum: 0,
TxNum: 0,
}

var s1, s2 *snapshotRecord = &s0, &s0 // snapshot records
var s1, s2 *snapshotRecord = nil, nil // snapshot records
var k string // key
var err error

Expand Down Expand Up @@ -233,9 +226,9 @@ func newDiffRecord(namespace string, record1 *privacyenabledstate.SnapshotRecord

// snapshotRecord represents the data of a snapshot record in json
type snapshotRecord struct {
Value string `json:"value,omitempty"`
BlockNum uint64 `json:"blockNum,omitempty"`
TxNum uint64 `json:"txNum,omitempty"`
Value string `json:"value"`
BlockNum uint64 `json:"blockNum"`
TxNum uint64 `json:"txNum"`
}

// Creates a new SnapshotRecord
Expand Down
38 changes: 15 additions & 23 deletions internal/ledger/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestCompare(t *testing.T) {
},
{
namespace: "ns3", key: "k1", value: "v4",
blockNum: 2, txNum: 1, metadata: "md4",
blockNum: 2, txNum: 0, metadata: "md4",
},
}

Expand All @@ -72,7 +72,7 @@ func TestCompare(t *testing.T) {
},
{
namespace: "ns3", key: "k1", value: "v4",
blockNum: 2, txNum: 1, metadata: "md4",
blockNum: 2, txNum: 0, metadata: "md4",
},
}

Expand All @@ -87,7 +87,7 @@ func TestCompare(t *testing.T) {
},
{
namespace: "ns3", key: "k1", value: "v4",
blockNum: 2, txNum: 1, metadata: "md4",
blockNum: 2, txNum: 0, metadata: "md4",
},
}

Expand Down Expand Up @@ -177,14 +177,14 @@ func TestCompare(t *testing.T) {
"blockNum" : 1,
"txNum" : 1
},
"snapshotrecord2" : {}
"snapshotrecord2" : null
}
]`
expectedMissingResult2 := `[
{
"namespace" : "ns1",
"key" : "k2",
"snapshotrecord1" : {},
"snapshotrecord1" : null,
"snapshotrecord2" : {
"value" : "v2",
"blockNum" : 1,
Expand All @@ -201,24 +201,24 @@ func TestCompare(t *testing.T) {
"blockNum" : 1,
"txNum" : 2
},
"snapshotrecord2" : {}
"snapshotrecord2" : null
},
{
"namespace" : "ns3",
"key" : "k1",
"snapshotrecord1" : {
"value" : "v4",
"blockNum" : 2,
"txNum" : 1
"txNum" : 0
},
"snapshotrecord2" : {}
"snapshotrecord2" : null
}
]`
expectedMissingTailResult2 := `[
{
"namespace" : "ns2",
"key" : "k1",
"snapshotrecord1" : {},
"snapshotrecord1" : null,
"snapshotrecord2" : {
"value" : "v3",
"blockNum" : 1,
Expand All @@ -228,11 +228,11 @@ func TestCompare(t *testing.T) {
{
"namespace" : "ns3",
"key" : "k1",
"snapshotrecord1" : {},
"snapshotrecord1" : null,
"snapshotrecord2" : {
"value" : "v4",
"blockNum" : 2,
"txNum" : 1
"txNum" : 0
}
}
]`
Expand Down Expand Up @@ -454,20 +454,12 @@ func TestJSONArrayFileWriter(t *testing.T) {
BlockNum: 472,
TxNum: 61,
},
Record2: &snapshotRecord{
Value: "",
BlockNum: 0,
TxNum: 0,
},
Record2: nil,
},
{
Namespace: "xyz",
Key: "key-44",
Record1: &snapshotRecord{
Value: "",
BlockNum: 0,
TxNum: 0,
},
Record1: nil,
Record2: &snapshotRecord{
Value: "purple",
BlockNum: 566,
Expand Down Expand Up @@ -499,12 +491,12 @@ func TestJSONArrayFileWriter(t *testing.T) {
"blockNum" : 472,
"txNum" : 61
},
"snapshotrecord2" : {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an intentional entry that was chosen to represent a missing record. Unless there is a strong reason, I would prefer to keep it as is.

"snapshotrecord2" : null
},
{
"namespace" : "xyz",
"key" : "key-44",
"snapshotrecord1" : {},
"snapshotrecord1" : null,
"snapshotrecord2" : {
"value" : "purple",
"blockNum" : 566,
Expand Down