Skip to content

Commit

Permalink
refactored unit tests to separate address and transaction and adjust …
Browse files Browse the repository at this point in the history
…sign_raw to match new return type
  • Loading branch information
jaxlotl committed May 26, 2022
1 parent 427966e commit 1f9b644
Show file tree
Hide file tree
Showing 7 changed files with 339 additions and 342 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ jobs:
"x86_64-linux-dbg")
make check -j"$(getconf _NPROCESSORS_ONLN)" V=1
python3 tooltests.py
./bindings/py_wrappers/pytest/cython_tests.sh
./bindings/python/pytest/cython_tests.sh
;;
"i686-linux")
make check -j"$(getconf _NPROCESSORS_ONLN)" V=1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ test-suite.log
libdogecoin.egg-info/
**/libdogecoin.c
dist/
!bindings/golang/libdogecoin/go.mod
157 changes: 157 additions & 0 deletions bindings/golang/libdogecoin/address_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package libdogecoin

import (
"testing"
)

func TestAddress(t *testing.T) {
t.Run("keypair_gen_mainnet", func(t *testing.T) {
priv, pub := w_generate_priv_pub_keypair(false)
if len(priv) == 0 {
t.Errorf("Private key does not exist.")
}
if len(pub) == 0 {
t.Errorf("Public key does not exist.")
}
})

t.Run("keypair_gen_testnet", func(t *testing.T) {
priv, pub := w_generate_priv_pub_keypair(true)
if len(priv) == 0 {
t.Errorf("Private key does not exist.")
}
if len(pub) == 0 {
t.Errorf("Public key does not exist.")
}
})

t.Run("p2pkh_addr_format_is_valid_mainnet", func(t *testing.T) {
_, pub := w_generate_priv_pub_keypair(false)
len := len(pub)
if !w_verify_p2pkh_address(pub, len) {
t.Errorf("P2PKH address is not valid.")
}
})

t.Run("p2pkh_addr_format_is_valid_testnet", func(t *testing.T) {
_, pub := w_generate_priv_pub_keypair(true)
len := len(pub)
if !w_verify_p2pkh_address(pub, len) {
t.Errorf("P2PKH address is not valid.")
}
})

t.Run("keypair_is_valid_mainnet", func(t *testing.T) {
priv, pub := w_generate_priv_pub_keypair(false)
if !w_verify_priv_pub_keypair(priv, pub, false) {
t.Errorf("Keypair is not valid.")
}
})

t.Run("keypair_is_valid_testnet", func(t *testing.T) {
priv, pub := w_generate_priv_pub_keypair(true)
if !w_verify_priv_pub_keypair(priv, pub, true) {
t.Errorf("Keypair is not valid.")
}
})

t.Run("master_keypair_gen_mainnet", func(t *testing.T) {
priv, pub := w_generate_hd_master_pub_keypair(false)
if len(priv) == 0 {
t.Errorf("Master private key does not exist.")
}
if len(pub) == 0 {
t.Errorf("Master public key does not exist.")
}
})

t.Run("master_keypair_gen_testnet", func(t *testing.T) {
priv, pub := w_generate_hd_master_pub_keypair(true)
if len(priv) == 0 {
t.Errorf("Master private key does not exist.")
}
if len(pub) == 0 {
t.Errorf("Master public key does not exist.")
}
})

t.Run("master_p2pkh_addr_format_is_valid_mainnet", func(t *testing.T) {
_, pub := w_generate_hd_master_pub_keypair(false)
len := len(pub)
if !w_verify_p2pkh_address(pub, len) {
t.Errorf("Master P2PKH address is not valid.")
}
})

t.Run("master_p2pkh_addr_format_is_valid_testnet", func(t *testing.T) {
_, pub := w_generate_hd_master_pub_keypair(true)
len := len(pub)
if !w_verify_p2pkh_address(pub, len) {
t.Errorf("Master P2PKH address is not valid.")
}
})

t.Run("master_keypair_is_valid_mainnet", func(t *testing.T) {
priv, pub := w_generate_hd_master_pub_keypair(false)
if !w_verify_hd_master_pub_keypair(priv, pub, false) {
t.Errorf("Master keypair is not valid.")
}
})

t.Run("master_keypair_is_valid_testnet", func(t *testing.T) {
priv, pub := w_generate_hd_master_pub_keypair(true)
if !w_verify_hd_master_pub_keypair(priv, pub, true) {
t.Errorf("Master keypair is not valid.")
}
})

t.Run("derived_hd_pubkey_gen_mainnet", func(t *testing.T) {
priv, _ := w_generate_hd_master_pub_keypair(false)
child_pub := w_generate_derived_hd_pub_key(priv)
if len(child_pub) == 0 {
t.Errorf("Derived public key does not exist.")
}
})

t.Run("derived_hd_pubkey_gen_testnet", func(t *testing.T) {
priv, _ := w_generate_hd_master_pub_keypair(true)
child_pub := w_generate_derived_hd_pub_key(priv)
if len(child_pub) == 0 {
t.Errorf("Derived public key does not exist.")
}
})

t.Run("derived_keypair_is_valid_mainnet", func(t *testing.T) {
priv, _ := w_generate_hd_master_pub_keypair(false)
child_pub := w_generate_derived_hd_pub_key(priv)
if !w_verify_hd_master_pub_keypair(priv, child_pub, false) {
t.Errorf("Derived keypair is not valid.")
}
})

t.Run("derived_keypair_is_valid_testnet", func(t *testing.T) {
priv, _ := w_generate_hd_master_pub_keypair(true)
child_pub := w_generate_derived_hd_pub_key(priv)
if !w_verify_hd_master_pub_keypair(priv, child_pub, true) {
t.Errorf("Derived keypair is not valid.")
}
})

t.Run("derived_p2pkh_addr_is_valid_mainnet", func(t *testing.T) {
priv, _ := w_generate_hd_master_pub_keypair(false)
child_pub := w_generate_derived_hd_pub_key(priv)
len := len(child_pub)
if !w_verify_p2pkh_address(child_pub, len) {
t.Errorf("Derived P2PKH address is not valid.")
}
})

t.Run("derived_p2pkh_addr_is_valid_testnet", func(t *testing.T) {
priv, _ := w_generate_hd_master_pub_keypair(true)
child_pub := w_generate_derived_hd_pub_key(priv)
len := len(child_pub)
if !w_verify_p2pkh_address(child_pub, len) {
t.Errorf("Derived P2PKH address is not valid.")
}
})
}
3 changes: 3 additions & 0 deletions bindings/golang/libdogecoin/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module libdogecoin

go 1.18
6 changes: 5 additions & 1 deletion bindings/golang/libdogecoin/libdogecoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ func w_sign_raw_transaction(input_index int, incoming_raw_tx string, script_hex
c_sig_hash_type := C.int(sig_hash_type)
c_amount := C.int(amount)
c_privkey := C.CString(privkey)
result = C.GoString(C.sign_raw_transaction(c_input_index, &c_incoming_raw_tx[0], c_script_hex, c_sig_hash_type, c_amount, c_privkey))
if C.sign_raw_transaction(c_input_index, &c_incoming_raw_tx[0], c_script_hex, c_sig_hash_type, c_amount, c_privkey) == 1 {
result = C.GoString(&c_incoming_raw_tx[0])
} else {
result = ""
}
C.free(unsafe.Pointer(c_script_hex))
C.free(unsafe.Pointer(c_privkey))
return
Expand Down
Loading

0 comments on commit 1f9b644

Please sign in to comment.