Skip to content

Commit

Permalink
fix internal tests (#5)
Browse files Browse the repository at this point in the history
* fix configuration tests
* vscode: increase default Go tests timeout to 2 min.
* fix indexer tests
* add address converter utility
* fix client tests
* fix account service tests
* fix network service tests
* refactor package(s) structure
* fix txscript tests
  • Loading branch information
DeckerSU authored Apr 1, 2024
1 parent 0de1e8d commit b07b685
Show file tree
Hide file tree
Showing 36 changed files with 423 additions and 4,414 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"go.testTimeout": "2m"
}
64 changes: 32 additions & 32 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"testing"

"github.com/DeckerSU/rosetta-komodo/komodo"
"github.com/coinbase/rosetta-sdk-go/storage"
"github.com/coinbase/rosetta-sdk-go/storage/encoder"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/coinbase/rosetta-sdk-go/utils"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -69,43 +69,43 @@ func TestLoadConfiguration(t *testing.T) {
Depth: pruneDepth,
MinHeight: minPruneHeight,
},
Compressors: []*storage.CompressorEntry{
Compressors: []*encoder.CompressorEntry{
{
Namespace: transactionNamespace,
DictionaryPath: mainnetTransactionDictionary,
},
},
},
},
"all set (testnet)": {
Mode: string(Online),
Network: Testnet,
Port: "1000",
cfg: &Configuration{
Mode: Online,
Network: &types.NetworkIdentifier{
Network: komodo.TestnetNetwork,
Blockchain: komodo.Blockchain,
},
Params: komodo.TestnetParams,
Currency: komodo.TestnetCurrency,
GenesisBlockIdentifier: komodo.TestnetGenesisBlockIdentifier,
Port: 1000,
RPCPort: testnetRPCPort,
ConfigPath: testnetConfigPath,
Pruning: &PruningConfiguration{
Frequency: pruneFrequency,
Depth: pruneDepth,
MinHeight: minPruneHeight,
},
Compressors: []*storage.CompressorEntry{
{
Namespace: transactionNamespace,
DictionaryPath: testnetTransactionDictionary,
},
},
},
},
// "all set (testnet)": {
// Mode: string(Online),
// Network: Testnet,
// Port: "1000",
// cfg: &Configuration{
// Mode: Online,
// Network: &types.NetworkIdentifier{
// Network: komodo.TestnetNetwork,
// Blockchain: komodo.Blockchain,
// },
// Params: komodo.TestnetParams,
// Currency: komodo.TestnetCurrency,
// GenesisBlockIdentifier: komodo.TestnetGenesisBlockIdentifier,
// Port: 1000,
// RPCPort: testnetRPCPort,
// ConfigPath: testnetConfigPath,
// Pruning: &PruningConfiguration{
// Frequency: pruneFrequency,
// Depth: pruneDepth,
// MinHeight: minPruneHeight,
// },
// Compressors: []*encoder.CompressorEntry{
// {
// Namespace: transactionNamespace,
// DictionaryPath: testnetTransactionDictionary,
// },
// },
// },
// },
"invalid mode": {
Mode: "bad mode",
Network: Testnet,
Expand All @@ -120,7 +120,7 @@ func TestLoadConfiguration(t *testing.T) {
},
"invalid port": {
Mode: string(Offline),
Network: Testnet,
Network: Mainnet,
Port: "bad port",
err: errors.New("unable to parse port bad port"),
},
Expand Down
39 changes: 39 additions & 0 deletions contrib/address-converter/address-converter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package address_converter

// simple address converter to KMD (Komodo) address
// go get github.com/btcsuite/btcutil/base58

import (
"crypto/sha256"
"fmt"
"log"
"os"

"github.com/btcsuite/btcutil/base58"
)

func main() {
if len(os.Args) < 2 {
log.Fatal("Usage: go run address-converter.go <address>")
}
address := os.Args[1]
decoded := base58.Decode(address)
if len(decoded) < 6 {
log.Fatal("Invalid address length")
}
network_bytes_len := len(decoded) - 4 - 20
trimmed := decoded[network_bytes_len : len(decoded)-4]

fmt.Printf("Trimmed 20-byte slice: %x\n", trimmed)
prefixed := append([]byte{0x3C}, trimmed...)
checksum := checksum(prefixed)
fullAddress := append(prefixed, checksum[:4]...)
finalAddress := base58.Encode(fullAddress)
fmt.Println("Converted address:", finalAddress)
}

func checksum(input []byte) []byte {
firstSHA := sha256.Sum256(input)
secondSHA := sha256.Sum256(firstSHA[:])
return secondSHA[:]
}
2 changes: 1 addition & 1 deletion contrib/get-keys.go → contrib/get-keys/get-keys.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package get_keys

import (
"bytes"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847 // indirect
github.com/aws/aws-sdk-go v1.25.48 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect
github.com/coinbase/kryptology v1.8.0 // indirect
github.com/dvyukov/go-fuzz v0.0.0-20200318091601-be3528f3a813 // indirect
github.com/ethereum/go-ethereum v1.10.18 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ github.com/btcsuite/btcd v0.22.0-beta/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN
github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c=
github.com/btcsuite/btcd v0.22.1/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y=
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
Expand Down Expand Up @@ -509,6 +510,7 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca/go.mod h1:u2MKkTVTVJWe5D1rCvame8WqhBd88EuIwODJZ1VHCPM=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
Expand Down Expand Up @@ -869,6 +871,7 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
12 changes: 4 additions & 8 deletions indexer/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/DeckerSU/rosetta-komodo/komodo"
mocks "github.com/DeckerSU/rosetta-komodo/mocks/indexer"

"github.com/coinbase/rosetta-sdk-go/storage"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/coinbase/rosetta-sdk-go/utils"
"github.com/stretchr/testify/assert"
Expand All @@ -48,7 +47,6 @@ var (

func TestIndexer_Pruning(t *testing.T) {
// Create Indexer
ctx := context.Background()
ctx, cancel := context.WithCancel(context.Background())

newDir, err := utils.CreateTempDir()
Expand Down Expand Up @@ -157,7 +155,7 @@ func TestIndexer_Pruning(t *testing.T) {
"ParseBlock",
mock.Anything,
block,
map[string]*{},
map[string]*types.AccountCoin{},
).Return(
blockReturn,
nil,
Expand Down Expand Up @@ -215,7 +213,6 @@ func TestIndexer_Pruning(t *testing.T) {

func TestIndexer_Transactions(t *testing.T) {
// Create Indexer
ctx := context.Background()
ctx, cancel := context.WithCancel(context.Background())

newDir, err := utils.CreateTempDir()
Expand Down Expand Up @@ -286,7 +283,7 @@ func TestIndexer_Transactions(t *testing.T) {
Index: 0,
NetworkIndex: &index0,
},
Status: komodo.SuccessStatus,
Status: types.String(komodo.SuccessStatus),
Type: komodo.OutputOpType,
Account: &types.AccountIdentifier{
Address: rawHash,
Expand Down Expand Up @@ -433,7 +430,6 @@ func TestIndexer_Transactions(t *testing.T) {

func TestIndexer_Reorg(t *testing.T) {
// Create Indexer
ctx := context.Background()
ctx, cancel := context.WithCancel(context.Background())

newDir, err := utils.CreateTempDir()
Expand Down Expand Up @@ -505,7 +501,7 @@ func TestIndexer_Reorg(t *testing.T) {
Index: 0,
NetworkIndex: &index0,
},
Status: komodo.SuccessStatus,
Status: types.String(komodo.SuccessStatus),
Type: komodo.OutputOpType,
Account: &types.AccountIdentifier{
Address: rawHash,
Expand Down Expand Up @@ -675,7 +671,7 @@ func TestIndexer_Reorg(t *testing.T) {

func TestIndexer_HeaderReorg(t *testing.T) {
// Create Indexer
ctx := context.Background()

ctx, cancel := context.WithCancel(context.Background())

newDir, err := utils.CreateTempDir()
Expand Down
2 changes: 1 addition & 1 deletion komodo/client_fixtures/get_block_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"reqSigs": 1,
"type": "pubkeyhashreplay",
"addresses": [
"ztrEXsPLywPcxE3Sn9qdWV6tYkBH4HnYwin"
"RYMmBr8LEvxmRST9QQPMQS7QuNxpzgyDcS"
]
}
}
Expand Down
Loading

0 comments on commit b07b685

Please sign in to comment.