Skip to content

Commit 02290a3

Browse files
committed
small fixes
1 parent 7a0699b commit 02290a3

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

src/core/block_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package core
2+
3+
import (
4+
"SilentPaymentAppBackend/src/common/types"
5+
"SilentPaymentAppBackend/src/testhelpers"
6+
"fmt"
7+
"log"
8+
"testing"
9+
)
10+
11+
func TestBlockAnalysis(t *testing.T) {
12+
var block types.Block
13+
err := testhelpers.LoadBlockFromFile("/Users/setorblagogee/dev/sp-test-dir/block-716120.json", &block)
14+
if err != nil {
15+
log.Fatalln(err)
16+
}
17+
18+
tweaks, err := ComputeTweaksForBlock(&block)
19+
if err != nil {
20+
log.Fatalln(err)
21+
}
22+
23+
for _, tweak := range tweaks {
24+
fmt.Printf("%x - %s\n", tweak.TweakData, tweak.Txid)
25+
}
26+
27+
for _, tx := range block.Txs {
28+
for _, tweak := range tweaks {
29+
if tx.Txid == tweak.Txid {
30+
fmt.Printf("%x\n", tweak.TweakData)
31+
}
32+
}
33+
}
34+
35+
}

src/core/tweak.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func ComputeTweakPerTx(tx types.Transaction) (*types.Tweak, error) {
270270
summedKey, err := sumPublicKeys(pubKeys)
271271
if err != nil {
272272
if strings.Contains(err.Error(), "not on secp256k1 curve") {
273-
common.WarningLogger.Println(err)
273+
common.WarningLogger.Println(err, "-", tx.Txid)
274274
return nil, nil
275275
}
276276
common.DebugLogger.Println("tx:", tx.Txid)

src/testhelpers/testhelpers.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"encoding/hex"
77
"encoding/json"
88
"fmt"
9-
"io/ioutil"
109
"log"
10+
"os"
1111
"testing"
1212
)
1313

@@ -91,7 +91,7 @@ func LoadCaseData(t *testing.T) ([]TestCase, error) {
9191
filePath := "../test_data/send_and_receive_test_vectors_with_type.json"
9292

9393
// Read the JSON file
94-
data, err := ioutil.ReadFile(filePath)
94+
data, err := os.ReadFile(filePath)
9595
if err != nil {
9696
t.Errorf("Error reading JSON file: %s", err)
9797
return nil, err
@@ -109,10 +109,21 @@ func LoadCaseData(t *testing.T) ([]TestCase, error) {
109109
return testCases, err
110110
}
111111

112-
func LoadAndUnmarshalBlockFromFile(filePath string, block *types.Block) error {
112+
func LoadBlockFromFile(filePath string, block *types.Block) error {
113+
// Read the JSON file
114+
data, err := os.ReadFile(filePath)
115+
if err != nil {
116+
log.Println(err)
117+
return err
118+
}
113119

120+
// Unmarshal the JSON data into the struct
121+
return json.Unmarshal(data, &block)
122+
}
123+
124+
func LoadAndUnmarshalBlockFromFile(filePath string, block *types.Block) error {
114125
// Read the JSON file
115-
data, err := ioutil.ReadFile(filePath)
126+
data, err := os.ReadFile(filePath)
116127
if err != nil {
117128
log.Println(err)
118129
return err

0 commit comments

Comments
 (0)