Skip to content

Commit

Permalink
invoke the statediff command properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk committed Sep 9, 2020
1 parent a5afd83 commit 2a3743f
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions conformance/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ func executeMessageVector(t *testing.T, vector *schema.TestVector) {

// Once all messages are applied, assert that the final state root matches
// the expected postcondition root.
if root != vector.Post.StateTree.RootCID {
if expected, actual := vector.Post.StateTree.RootCID, root; expected != actual {
t.Logf("actual state root CID doesn't match expected one; expected: %s, actual: %s", expected, actual)
dumpThreeWayStateDiff(t, vector, bs, root)
t.FailNow()
}
}

Expand Down Expand Up @@ -239,8 +241,10 @@ func executeTipsetVector(t *testing.T, vector *schema.TestVector) {

// Once all messages are applied, assert that the final state root matches
// the expected postcondition root.
if root != vector.Post.StateTree.RootCID {
if expected, actual := vector.Post.StateTree.RootCID, root; expected != actual {
t.Logf("actual state root CID doesn't match expected one; expected: %s, actual: %s", expected, actual)
dumpThreeWayStateDiff(t, vector, bs, root)
t.FailNow()
}
}

Expand Down Expand Up @@ -290,26 +294,30 @@ func dumpThreeWayStateDiff(t *testing.T, vector *schema.TestVector, bs blockstor
d1 = color.New(color.FgGreen, color.Bold).Sprint("[Δ1]")
d2 = color.New(color.FgGreen, color.Bold).Sprint("[Δ2]")
d3 = color.New(color.FgGreen, color.Bold).Sprint("[Δ3]")

cmd *exec.Cmd
)

printDiff := func(left, right cid.Cid) {
cmd := exec.Command("statediff", "car", "--file", tmpCar, left.String(), right.String())
b, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("statediff failed: %s", err)
}
t.Log(string(b))
}

bold := color.New(color.Bold).SprintfFunc()

// run state diffs.
t.Log(bold("=== dumping 3-way diffs between %s, %s, %s ===", a, b, c))

t.Log(bold("--- %s left: %s; right: %s ---", d1, a, b))
cmd = exec.Command("statediff", tmpCar, vector.Post.StateTree.RootCID.String(), actual.String())
t.Log(cmd.CombinedOutput())
printDiff(vector.Post.StateTree.RootCID, actual)

t.Log(bold("--- %s left: %s; right: %s ---", d2, c, b))
cmd = exec.Command("statediff", tmpCar, vector.Pre.StateTree.RootCID.String(), actual.String())
t.Log(cmd.CombinedOutput())
printDiff(vector.Pre.StateTree.RootCID, actual)

t.Log(bold("--- %s left: %s; right: %s ---", d3, c, a))
cmd = exec.Command("statediff", tmpCar, vector.Pre.StateTree.RootCID.String(), vector.Post.StateTree.RootCID.String())
t.Log(cmd.CombinedOutput())
printDiff(vector.Pre.StateTree.RootCID, vector.Post.StateTree.RootCID)
}

// writeStateToTempCAR writes the provided roots to a temporary CAR that'll be
Expand Down

0 comments on commit 2a3743f

Please sign in to comment.