Skip to content

Commit

Permalink
testify linter
Browse files Browse the repository at this point in the history
Signed-off-by: Darren Kellenschwiler <deggen@kschw.com>
  • Loading branch information
sirdeggen committed Oct 24, 2023
1 parent 9ba8665 commit 54550c2
Show file tree
Hide file tree
Showing 20 changed files with 185 additions and 179 deletions.
16 changes: 8 additions & 8 deletions block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/libsv/go-bt/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/libsv/go-bc"
)
Expand All @@ -24,8 +24,8 @@ func TestNewBlock(t *testing.T) {
blockBytes := "0000002043453154ad6d8209030ada359e07d2ce354cbed1f6169db497a5f2726e0bb51df5bc41a43429c7469dbb3501a186bf1f9238f9e886f84da057e7571c3472d12af33a1561ffff7f20010000000202000000010000000000000000000000000000000000000000000000000000000000000000ffffffff05024c0b0101ffffffff0106270000000000002321033ac208f182e7fe982b1c25027ada05e6fc44590e3f862b0a8422eda03ea5951bac00000000020000000353d4f38490033f3baf11135175c011c61db6cb3e1d9c8d5579da464bd6d7500d000000004847304402205069ed8be3ea22953232328f4594b542655211ce103261ec9278900f8e4a7844022017baa239129970ab92dc4f3f18626954a298e179cc41457e94ea26232fa60de741feffffffd6db9360d48d9084e60d9e9e93ee187ec785768fc38a1826224cda54b436c198000000004847304402203a322b5c2145a8c6194f7575684cf877504a08e07c6718b633c1c7a88bfb71f3022079a87efe2bed70d886cd82f7c747b20a148c79f5adcaec1da05cc18df615fcee41feffffff07c023d3e3bc13b64025000002d2c565521b418562ae0e92e18553c5fafbc781010000006b483045022100abd8d9aed279921efe7be9fd9e24ff2e80b223106355a2e67ecb545cdfbfbf1002207c3861d13bbb08b4aa8e6d5f075f7505a70b98469c4b586c1674bd62b73cf8f2412102d86a9727d885baa389532bba48e37fc529c797939204c78d441a122b2f7a5c32feffffff02bd440f00000000001976a9142621c6863e947d83172bc677640d88cbe5b2477d88aca0860100000000001976a914b85524abf8202a961b847a3bd0bc89d3d4d41cc588ac4b0b0000"
b, err := bc.NewBlockFromStr(blockBytes)

assert.NoError(t, err)
assert.Equal(t, eb, b)
require.NoError(t, err)
require.Equal(t, eb, b)
}

func TestBlockString(t *testing.T) {
Expand All @@ -41,14 +41,14 @@ func TestBlockString(t *testing.T) {
Txs: txs,
}

assert.Equal(t, expectedBlock, b.String())
require.Equal(t, expectedBlock, b.String())
}

func TestBlockStringAndBytesMatch(t *testing.T) {
blockStr := "000000208340568a93304c2b327d901fde726e26825a753e9d9681697d60f13b5033691540dddb67dc3caf63b5ac5945e62eed5e7b328901c3bad1be775ca773152be5f8023d1561ffff7f20000000000302000000010000000000000000000000000000000000000000000000000000000000000000ffffffff05024e0b0101ffffffff01cc28000000000000232102af5e52d92723981deef3865309f04807a4cb16cc3da8270b203e482c43a370feac00000000020000000372545d8b76a366701abf79c5219a2f70748c2f888e933b82ada34ed070e66d2100000000494830450221009e8c1ec9c0bb567c47e153946c48dbb1c904d892dd149f92721d9fe87b816f1702207584a0fa85d39056a55685e2c7a1ed6f663b995670bc17fefc00b8ed781591d841feffffffef6f13ab6366f7a670869505630fdee12338ef12efbb223e223b44115f3c273100000000484730440220303ebd18633704633c3b92f261173fa833ca0376578e6d54c213d058c42c6716022077ec705a52337011cd7dd86ebcd207e613618b3da1252bae19355ad45cc04acd41feffffffad5cf4c165fde449155b4de8d1eee9f65e9bb66ff7665f4cb4788a38d665adcc010000006b483045022100ac2e344a9ec980b0c2625a5784c17e62ee59b674a146e6268ae56d49016b57e202202e2e7beb60d879148fdb3f0ed98b7b1148780bb31d82794cddc1c4a2f77d1ed5412102b691a69957cf30c1a7ceae9ba719d5f8891662623f0e797146446df73aa83872feffffff02a0860100000000001976a914b85524abf8202a961b847a3bd0bc89d3d4d41cc588acbd440f00000000001976a914fe88c4aeccc229c1bf9913e65fc6ff22f6c9d1fe88ac4d0b000002000000038bf51c82898c0f633f3bab38cdc737a4f666a3640c7128151d6d14bfa911aeb9000000004948304502210095cb2822a8ac066e074a06bf299fd4d2724f869e27e85b02365c2ba54da34e6902202191ffa313b9c4cf55d4893a18e99108d20720bafbbc7c5486238c1e502b254f41feffffffbbba0582b6dc50cce76a0b9d5e00e0cb3afa656db5000eeabad69c3c7b045b860000000049483045022100833865334ae594028a00460dd90575047cdfb9e40d3517051f4841a76035898e0220330e1321e99a59481513978d3fcd34db7b178c8f318176a0eccc0cdb308293a141feffffff5e6584b9ccc112673740ad8fe0f98db8b57585da611a727938fc6702c595827f000000006b483045022100e07f8411e6fd3fdc9ebc9360df6a18a45e49ce80f7e34f387930a16f07d3df6202206eba79ebe9e3760bdb21fa0bb10e4087a51bae88af8b16038d27b89256f9529e412103ba0acf181c9c111451fc5201b8008c33348b49f0b8337e6575312a39eb16852ffeffffff02bd440f00000000001976a914b7a6f23683c5570019094d61429c3c9cbe64533088aca0860100000000001976a914b85524abf8202a961b847a3bd0bc89d3d4d41cc588ac4d0b0000"
b, err := bc.NewBlockFromStr(blockStr)
assert.NoError(t, err)
assert.Equal(t, hex.EncodeToString(b.Bytes()), b.String())
require.NoError(t, err)
require.Equal(t, hex.EncodeToString(b.Bytes()), b.String())
}

func TestBlockInvalid(t *testing.T) {
Expand All @@ -69,8 +69,8 @@ func TestBlockInvalid(t *testing.T) {
for name, test := range tests {
t.Run(name, func(t *testing.T) {
_, err := bc.NewBlockFromStr(test.expectedBlock)
assert.Error(t, err)
assert.EqualError(t, err, test.expErr.Error())
require.Error(t, err)
require.EqualError(t, err, test.expErr.Error())
})
}
}
45 changes: 23 additions & 22 deletions blockheader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/libsv/go-bc"
)
Expand All @@ -33,8 +34,8 @@ func TestNewBlockHeader(t *testing.T) {
headerBytes := "0000002074a17794e7890e9124d87e122b7f67b9d707dcb6c5b9d542b22eff3d13054678e9d8afa92026c2c0873524b18cbf2479720a8471952770c847d9ec8e1e939dfc1f593460ffff7f2000000000"
bh, err := bc.NewBlockHeaderFromStr(headerBytes)

assert.NoError(t, err)
assert.Equal(t, ebh, bh)
require.NoError(t, err)
require.Equal(t, ebh, bh)
}

func TestBlockHeaderString(t *testing.T) {
Expand All @@ -58,14 +59,14 @@ func TestBlockHeaderString(t *testing.T) {
Nonce: 0,
}

assert.Equal(t, expectedHeader, bh.String())
require.Equal(t, expectedHeader, bh.String())
}

func TestBlockHeaderStringAndBytesMatch(t *testing.T) {
headerStr := "0000002074a17794e7890e9124d87e122b7f67b9d707dcb6c5b9d542b22eff3d13054678e9d8afa92026c2c0873524b18cbf2479720a8471952770c847d9ec8e1e939dfc1f593460ffff7f2000000000"
bh, err := bc.NewBlockHeaderFromStr(headerStr)
assert.NoError(t, err)
assert.Equal(t, hex.EncodeToString(bh.Bytes()), bh.String())
require.NoError(t, err)
require.Equal(t, hex.EncodeToString(bh.Bytes()), bh.String())
}

func TestBlockHeaderInvalid(t *testing.T) {
Expand All @@ -90,8 +91,8 @@ func TestBlockHeaderInvalid(t *testing.T) {
for name, test := range tests {
t.Run(name, func(t *testing.T) {
_, err := bc.NewBlockHeaderFromStr(test.expectedHeader)
assert.Error(t, err)
assert.EqualError(t, err, test.expErr.Error())
require.Error(t, err)
require.EqualError(t, err, test.expErr.Error())
})
}
}
Expand All @@ -101,33 +102,33 @@ func TestExtractMerkleRootFromBlockHeader(t *testing.T) {

merkleRoot, err := bc.ExtractMerkleRootFromBlockHeader(header)

assert.NoError(t, err)
assert.Equal(t, merkleRoot, "96cbb75fd2ef98e4309eebc8a54d2386333d936ded2a0f3e06c23a91bb612f70")
require.NoError(t, err)
require.Equal(t, "96cbb75fd2ef98e4309eebc8a54d2386333d936ded2a0f3e06c23a91bb612f70", merkleRoot)
}

func TestEncodeAndDecodeBlockHeader(t *testing.T) {
// the genesis block
genesisHex := "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c"
genesis, err := bc.NewBlockHeaderFromStr(genesisHex)
assert.NoError(t, err)
assert.Equal(t, genesisHex, genesis.String())
require.NoError(t, err)
require.Equal(t, genesisHex, genesis.String())
}

func TestVerifyBlockHeader(t *testing.T) {
// the genesis block
genesisHex := "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c"
header, err := hex.DecodeString(genesisHex)
assert.NoError(t, err)
require.NoError(t, err)
genesis, err := bc.NewBlockHeaderFromBytes(header)
assert.NoError(t, err)
require.NoError(t, err)

assert.Equal(t, genesisHex, genesis.String())
require.Equal(t, genesisHex, genesis.String())
assert.True(t, genesis.Valid())

// change one letter
header[0] = 222
genesisInvalid, err := bc.NewBlockHeaderFromBytes(header)
assert.NoError(t, err)
require.NoError(t, err)
assert.False(t, genesisInvalid.Valid())
}

Expand Down Expand Up @@ -186,8 +187,8 @@ func TestBlockHeader_MarshalJSON(t *testing.T) {
for name, test := range tests {
t.Run(name, func(t *testing.T) {
bhj, err := json.MarshalIndent(test.bh, "", "\t")
assert.NoError(t, err)
assert.Equal(t, test.expJSON, string(bhj))
require.NoError(t, err)
require.Equal(t, test.expJSON, string(bhj))
})
}
}
Expand Down Expand Up @@ -232,15 +233,15 @@ func TestBlockHeader_UnmarshalJSON(t *testing.T) {
t.Run(name, func(t *testing.T) {
b, err := json.Marshal(test.bh)
if test.err != nil {
assert.Error(t, err)
assert.EqualError(t, err, test.err.Error())
require.Error(t, err)
require.EqualError(t, err, test.err.Error())
return
}
assert.NoError(t, err)
require.NoError(t, err)

var bh *bc.BlockHeader
assert.NoError(t, json.Unmarshal(b, &bh))
assert.Equal(t, test.bh.String(), bh.String())
require.NoError(t, json.Unmarshal(b, &bh))
require.Equal(t, test.bh.String(), bh.String())
})
}
}
46 changes: 23 additions & 23 deletions merklepath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/libsv/go-bc"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestBuildingMerklePathBinary(t *testing.T) {
Expand Down Expand Up @@ -36,7 +36,7 @@ func TestBuildingMerklePathBinary(t *testing.T) {
}

// assert binary path is expected.
assert.Equal(t, mp, merklePathBinary)
require.Equal(t, mp, merklePathBinary)
}

func TestDecodingMerklePathBinary(t *testing.T) {
Expand All @@ -58,12 +58,12 @@ func TestDecodingMerklePathBinary(t *testing.T) {
// }

// assert binary path is expected.
assert.Equal(t, uint64(136), merklePath.Index)
assert.Equal(t, 4, len(merklePath.Path))
assert.Equal(t, "6cf512411d03ab9b61643515e7aa9afd005bf29e1052ade95410b3475f02820c", merklePath.Path[0])
assert.Equal(t, "cd73c0c6bb645581816fa960fd2f1636062fcbf23cb57981074ab8d708a76e3b", merklePath.Path[1])
assert.Equal(t, "b4c8d919190a090e77b73ffcd52b85babaaeeb62da000473102aca7f070facef", merklePath.Path[2])
assert.Equal(t, "3470d882cf556a4b943639eba15dc795dffdbebdc98b9a98e3637fda96e3811e", merklePath.Path[3])
require.Equal(t, uint64(136), merklePath.Index)
require.Len(t, merklePath.Path, 4)
require.Equal(t, "6cf512411d03ab9b61643515e7aa9afd005bf29e1052ade95410b3475f02820c", merklePath.Path[0])
require.Equal(t, "cd73c0c6bb645581816fa960fd2f1636062fcbf23cb57981074ab8d708a76e3b", merklePath.Path[1])
require.Equal(t, "b4c8d919190a090e77b73ffcd52b85babaaeeb62da000473102aca7f070facef", merklePath.Path[2])
require.Equal(t, "3470d882cf556a4b943639eba15dc795dffdbebdc98b9a98e3637fda96e3811e", merklePath.Path[3])
}

func TestGetMerklePath(t *testing.T) {
Expand All @@ -81,19 +81,19 @@ func TestGetMerklePath(t *testing.T) {
expected := "1a1e779cd7dfc59f603b4e88842121001af822b2dc5d3b167ae66152e586a6b0"

merkles, err := bc.BuildMerkleTreeStore(txids)
assert.NoError(t, err)
require.NoError(t, err)

// build path for tx index 4.
path := bc.GetTxMerklePath(4, merkles)
root, err := bc.MerkleRootFromBranches("e3aa0230aa81abd483023886ad12790acf070e2a9f92d7f0ae3bebd90a904361", int(path.Index), path.Path)
assert.NoError(t, err)
assert.Equal(t, expected, root)
require.NoError(t, err)
require.Equal(t, expected, root)

// build path for tx index 3.
path = bc.GetTxMerklePath(3, merkles)
root, err = path.CalculateRoot("728714bbbddd81a54cae473835ae99eb92ed78191327eb11a9d7494273dcad2a")
assert.NoError(t, err)
assert.Equal(t, expected, root)
require.NoError(t, err)
require.Equal(t, expected, root)
}

func TestGetMerklePathOddPosition(t *testing.T) {
Expand All @@ -106,13 +106,13 @@ func TestGetMerklePathOddPosition(t *testing.T) {
}

merkles, err := bc.BuildMerkleTreeStore(txids)
assert.NoError(t, err)
require.NoError(t, err)

// build path for tx index 4.
path := bc.GetTxMerklePath(4, merkles)
root, err := bc.MerkleRootFromBranches("e3aa0230aa81abd483023886ad12790acf070e2a9f92d7f0ae3bebd90a904361", int(path.Index), path.Path)
assert.NoError(t, err)
assert.Equal(t, merkles[len(merkles)-1], root)
require.NoError(t, err)
require.Equal(t, merkles[len(merkles)-1], root)
}

func TestGetMerklePathEmptyPath(t *testing.T) {
Expand All @@ -121,15 +121,15 @@ func TestGetMerklePathEmptyPath(t *testing.T) {
}

merkles, err := bc.BuildMerkleTreeStore(txids)
assert.NoError(t, err)
require.NoError(t, err)

// build path for tx index 4.
path := bc.GetTxMerklePath(0, merkles)
root, err := bc.MerkleRootFromBranches("b6d4d13aa08bb4b6cdb3b329cef29b5a5d55d85a85c330d56fddbce78d99c7d6", int(path.Index), path.Path)
assert.NoError(t, err)
assert.Equal(t, merkles[len(merkles)-1], root)
assert.Equal(t, ([]string)(nil), path.Path)
assert.Equal(t, uint64(0), path.Index)
require.NoError(t, err)
require.Equal(t, merkles[len(merkles)-1], root)
require.Equal(t, ([]string)(nil), path.Path)
require.Equal(t, uint64(0), path.Index)
}

func TestGetMerklePathEmptyPathJson(t *testing.T) {
Expand All @@ -140,6 +140,6 @@ func TestGetMerklePathEmptyPathJson(t *testing.T) {
merkles, _ := bc.BuildMerkleTreeStore(txids)
path := bc.GetTxMerklePath(0, merkles)
js, err := json.Marshal(path)
assert.NoError(t, err)
assert.Equal(t, string(js), "{\"index\":0,\"path\":null}")
require.NoError(t, err)
require.Equal(t, "{\"index\":0,\"path\":null}", string(js))
}
6 changes: 3 additions & 3 deletions merkleproof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/hex"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/libsv/go-bc"
)
Expand Down Expand Up @@ -53,8 +53,8 @@ func TestMerkleProofBytes(t *testing.T) {

proof, err := test.merkleProofJSON.Bytes()

assert.NoError(t, err)
assert.Equal(t, expected, proof)
require.NoError(t, err)
require.Equal(t, expected, proof)
})
}
}
10 changes: 5 additions & 5 deletions merkleroot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bc_test
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/libsv/go-bc"
)
Expand All @@ -24,8 +24,8 @@ func TestBuildMerkleRoot(t *testing.T) {

root, err := bc.BuildMerkleRoot(txids)

assert.NoError(t, err)
assert.Equal(t, expected, root)
require.NoError(t, err)
require.Equal(t, expected, root)
}

func TestTxsToTxIDs(t *testing.T) {
Expand Down Expand Up @@ -53,6 +53,6 @@ func TestTxsToTxIDs(t *testing.T) {

txids, err := bc.TxsToTxIDs(txs)

assert.NoError(t, err)
assert.Equal(t, expected, txids)
require.NoError(t, err)
require.Equal(t, expected, txids)
}
8 changes: 4 additions & 4 deletions merkletreeparent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/hex"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/libsv/go-bc"
)
Expand All @@ -17,8 +17,8 @@ func TestGetMerkleTreeParentStr(t *testing.T) {

parent, err := bc.MerkleTreeParentStr(leftNode, rightNode)

assert.NoError(t, err)
assert.Equal(t, expected, parent)
require.NoError(t, err)
require.Equal(t, expected, parent)
}

func TestGetMerkleTreeParent(t *testing.T) {
Expand All @@ -29,5 +29,5 @@ func TestGetMerkleTreeParent(t *testing.T) {

parent := bc.MerkleTreeParent(leftNode, rightNode)

assert.Equal(t, expected, parent)
require.Equal(t, expected, parent)
}
Loading

0 comments on commit 54550c2

Please sign in to comment.