Skip to content

Commit

Permalink
Merge pull request #70 from libsv/fix/remove-dup-test
Browse files Browse the repository at this point in the history
fix linter queries
  • Loading branch information
deggen authored Sep 12, 2023
2 parents 29903d3 + 0edde17 commit df8a748
Show file tree
Hide file tree
Showing 21 changed files with 735 additions and 421 deletions.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ updates:
# Check for npm updates at 9am UTC (5am EST)
time: "10:00"
reviewers:
- "jadwahab"
- "sirdeggen"
assignees:
- "jadwahab"
- "sirdeggen"
# Labels must be created first
labels:
- "update"
12 changes: 0 additions & 12 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ pull_request_rules:
conditions:
- -draft
- author~=^dependabot(|-preview)\[bot\]$
- check-success='build (1.16.x, ubuntu-latest)'
- check-success='build (1.17.x, ubuntu-latest)'
- check-success='build (1.16.x, macos-latest)'
- check-success='build (1.17.x, macos-latest)'
- check-success='lint (1.16.x, ubuntu-latest)'
- check-success='lint (1.17.x, ubuntu-latest)'
- check-success='lint (1.16.x, macos-latest)'
- check-success='lint (1.17.x, macos-latest)'
- check-success='Analyze (go)'
- title~=^Bump [^\s]+ from ([\d]+)\..+ to \1\.
Expand All @@ -27,13 +23,9 @@ pull_request_rules:
- name: Alert on major version detection
conditions:
- author~=^dependabot(|-preview)\[bot\]$
- check-success='build (1.16.x, ubuntu-latest)'
- check-success='build (1.17.x, ubuntu-latest)'
- check-success='build (1.16.x, macos-latest)'
- check-success='build (1.17.x, macos-latest)'
- check-success='lint (1.16.x, ubuntu-latest)'
- check-success='lint (1.17.x, ubuntu-latest)'
- check-success='lint (1.16.x, macos-latest)'
- check-success='lint (1.17.x, macos-latest)'
- check-success='Analyze (go)'
- -title~=^Bump [^\s]+ from ([\d]+)\..+ to \1\.
Expand All @@ -49,13 +41,9 @@ pull_request_rules:
- name: Automatic Merge ⬇️ on Approval ✔
conditions:
- "#approved-reviews-by>=1"
- check-success='build (1.16.x, ubuntu-latest)'
- check-success='build (1.17.x, ubuntu-latest)'
- check-success='build (1.16.x, macos-latest)'
- check-success='build (1.17.x, macos-latest)'
- check-success='lint (1.16.x, ubuntu-latest)'
- check-success='lint (1.17.x, ubuntu-latest)'
- check-success='lint (1.16.x, macos-latest)'
- check-success='lint (1.17.x, macos-latest)'
- check-success='Analyze (go)'
- label!=work-in-progress
Expand Down
1 change: 1 addition & 0 deletions block.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package bc is a bitcoin blockchain library bc = block chain.
package bc

import (
Expand Down
12 changes: 6 additions & 6 deletions blockheader.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ Nonce 32-bit number (starts at 0) 4

// A BlockHeader in the Bitcoin blockchain.
type BlockHeader struct {
Version uint32
Time uint32
Nonce uint32
HashPrevBlock []byte
HashMerkleRoot []byte
Bits []byte
Version uint32 `json:"version"`
Time uint32 `json:"time"`
Nonce uint32 `json:"nonce"`
HashPrevBlock []byte `json:"hashPrevBlock"`
HashMerkleRoot []byte `json:"merkleRoot"`
Bits []byte `json:"bits"`
}

type bhJSON struct {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/libsv/go-bk v0.1.6
github.com/libsv/go-bt/v2 v2.2.5
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.2
github.com/stretchr/testify v1.8.4
)

require (
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
Expand Down
6 changes: 5 additions & 1 deletion spv/ancestry_binary.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Package spv is a simple payment verification library for Bitcoin SV.
// It is designed to be used by applications that need to verify payments
// without needing to run a full node. It uses TSC formats for the extended
// data required to verify an inbound transaction.
package spv

import (
Expand Down Expand Up @@ -136,7 +140,7 @@ func parseMapiCallbacks(b []byte) ([]*bc.MapiCallback, error) {
return mapiResponses, nil
}

func verifyInputOutputPair(tx *bt.Tx, lock *bscript.Script, unlock *bscript.Script) bool {
func verifyInputOutputPair(_ *bt.Tx, _ *bscript.Script, _ *bscript.Script) bool {
// TODO script interpreter.
return true
}
14 changes: 2 additions & 12 deletions spv/ancestry_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ func TestEnvelope_IsAnchored(t *testing.T) {
func TestEnvelope_Bytes_IsValid(t *testing.T) {
for name, test := range tests {
t.Run(name, func(t *testing.T) {
fmt.Println("------------------------------------------------------------------ Crunchy Nut ------------------------------------------------------------------")
j := []byte(test.jsonString)
var e Envelope
err := json.Unmarshal(j, &e)
Expand All @@ -258,7 +257,7 @@ func TestEnvelope_Bytes_IsValid(t *testing.T) {
assert.Error(t, err, "Couldn't decode hexString")
}

efromB, err := NewCrunchyNutEnvelopeFromBytes(b)
_, err = NewCrunchyNutEnvelopeFromBytes(b)
if err != nil {
assert.Error(t, err, "Couldn't create envelope from bytes")
}
Expand All @@ -268,14 +267,9 @@ func TestEnvelope_Bytes_IsValid(t *testing.T) {
assert.Error(t, err, "Couldn't convert envelope to bytes")
}

fmt.Printf("%v bytes: \n\n%+v\n\n", name, hex.EncodeToString(*bFromE))
fmt.Printf("e: \n\n%+v\n\n", e)
fmt.Printf("efromB: \n\n%+v\n\n", efromB)

assert.Equal(t, b, *bFromE)
assert.NoError(t, err)

fmt.Println("------------------------------------------------------------------ Special K ------------------------------------------------------------------")
j2 := []byte(test.jsonString)
var e2 Envelope
err2 := json.Unmarshal(j2, &e2)
Expand All @@ -288,7 +282,7 @@ func TestEnvelope_Bytes_IsValid(t *testing.T) {
assert.Error(t, err, "Couldn't decode hexString")
}

efromB2, err2 := NewSpecialKEnvelopeFromBytes(b2)
_, err2 = NewSpecialKEnvelopeFromBytes(b2)
if err2 != nil {
assert.Error(t, err, "Couldn't create envelope from bytes")
}
Expand All @@ -298,10 +292,6 @@ func TestEnvelope_Bytes_IsValid(t *testing.T) {
assert.Error(t, err, "Couldn't convert envelope to bytes")
}

fmt.Printf("%v bytes: \n\n%+v\n\n", name, hex.EncodeToString(*bFromE2))
fmt.Printf("e: \n\n%+v\n\n", e2)
fmt.Printf("efromB: \n\n%+v\n\n", efromB2)

assert.Equal(t, b2, *bFromE2)
assert.NoError(t, err2)
})
Expand Down
6 changes: 5 additions & 1 deletion spv/ancestry_tsc_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/libsv/go-bt/v2"
)

const (
h = "header"
)

// TSCAncestriesJSON spec at https://tsc.bitcoinassociation.net/standards/transaction-ancestors/ eventually.
type TSCAncestriesJSON []TSCAncestryJSON

Expand Down Expand Up @@ -105,7 +109,7 @@ func flagProofType(flags byte) string {
return "blockhash"
// if bit 1 of flags is set, target should contain a block header (80 bytes).
case 2:
return "header"
return h
default:
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion spv/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func flagType(flags byte) string {
return "blockhash"
// if bit 1 of flags is set, target should contain a block header (80 bytes).
case 2:
return "header"
return h
default:
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion spv/verifymerkleproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (v *verifier) VerifyMerkleProofJSON(ctx context.Context, proof *bc.MerklePr
}
merkleRoot = blockHeader.HashMerkleRootStr()

} else if proof.TargetType == "header" && len(proof.Target) == 160 {
} else if proof.TargetType == h && len(proof.Target) == 160 {
// The `target` field contains a block header
var err error
merkleRoot, err = bc.ExtractMerkleRootFromBlockHeader(proof.Target)
Expand Down
2 changes: 1 addition & 1 deletion spv/verifymerkleproof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type mockBlockHeaderChain struct{}

func (bhc *mockBlockHeaderChain) BlockHeader(ctx context.Context, blockHash string) (blockHeader *bc.BlockHeader, err error) {
func (bhc *mockBlockHeaderChain) BlockHeader(_ context.Context, _ string) (blockHeader *bc.BlockHeader, err error) {
return bc.NewBlockHeaderFromStr("000000208e33a53195acad0ab42ddbdbe3e4d9ca081332e5b01a62e340dbd8167d1a787b702f61bb913ac2063e0f2aed6d933d3386234da5c8eb9e30e498efd25fb7cb96fff12c60ffff7f2001000000")
}

Expand Down
17 changes: 9 additions & 8 deletions testing/data/data.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Package data contains test data for the spv package.
package data

import (
"embed"
"path"
)

// TestDataDir a directory container test data.
type TestDataDir struct {
// sataDirTests a directory container test data.
type dataDirTests struct {
prefix string
fs embed.FS
}
Expand All @@ -27,36 +28,36 @@ var spvVerifyData embed.FS
var blockHeaderData embed.FS

// SpvCreateData data for creating spv envelopes.
var SpvCreateData = TestDataDir{
var SpvCreateData = dataDirTests{
prefix: "spv/create",
fs: spvCreateData,
}

// SpvBinaryData data for creating spv envelopes.
var SpvBinaryData = TestDataDir{
var SpvBinaryData = dataDirTests{
prefix: "spv/binary",
fs: spvBinaryData,
}

// SpvSerialJSONData data for creating spv envelopes.
var SpvSerialJSONData = TestDataDir{
var SpvSerialJSONData = dataDirTests{
prefix: "spv/json",
fs: spvSerialJSONData,
}

// SpvVerifyData data for verifying spv envelopes.
var SpvVerifyData = TestDataDir{
var SpvVerifyData = dataDirTests{
prefix: "spv/verify",
fs: spvVerifyData,
}

// BlockHeaderData hash => block header mapping data.
var BlockHeaderData = TestDataDir{
var BlockHeaderData = dataDirTests{
prefix: "bhc",
fs: blockHeaderData,
}

// Load the data of a file.
func (d *TestDataDir) Load(file string) ([]byte, error) {
func (d *dataDirTests) Load(file string) ([]byte, error) {
return d.fs.ReadFile(path.Join(d.prefix, file))
}
36 changes: 18 additions & 18 deletions vendor/github.com/stretchr/testify/assert/assertion_compare.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit df8a748

Please sign in to comment.