Skip to content

Commit

Permalink
re-align test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenlanders committed Mar 21, 2024
1 parent 7f5d06a commit 69fce88
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions internal/mempool/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mempool
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"math/rand"
Expand Down Expand Up @@ -945,17 +946,24 @@ func TestAppendCheckTxErr(t *testing.T) {
}
t.Cleanup(client.Wait)
txmp := setup(t, client, 500)
existingLogData := `[{"log":"existing error log"}]`
newLogData := "sample error log"
existingData := `[{"log":"existing error log"}]`

// Append new error
actualResult := txmp.AppendCheckTxErr(existingLogData, newLogData)
expectedResult := fmt.Sprintf(`[{"log":"existing error log"},{"log":"%s"}]`, newLogData)
result := txmp.AppendCheckTxErr(existingData, "sample error msg")

require.Equal(t, expectedResult, actualResult)
// Unmarshal the result
var data []map[string]interface{}
err := json.Unmarshal([]byte(result), &data)
require.NoError(t, err)
require.Equal(t, len(data), 2)
require.Equal(t, data[1]["log"], "sample error msg")

// Append new error to empty log
actualResult = txmp.AppendCheckTxErr("", newLogData)
result = txmp.AppendCheckTxErr("", "sample error msg")

require.Equal(t, `[{"log":"sample error log"}]`, actualResult)
// Unmarshal the result
err = json.Unmarshal([]byte(result), &data)
require.NoError(t, err)
require.Equal(t, len(data), 1)
require.Equal(t, data[0]["log"], "sample error msg")
}

0 comments on commit 69fce88

Please sign in to comment.