Skip to content

Commit 2743e64

Browse files
committed
Set wallet data in unit tests
1 parent c35ddaf commit 2743e64

File tree

4 files changed

+82
-7
lines changed

4 files changed

+82
-7
lines changed

pkg/tbtc/chain_test.go

+17-4
Original file line numberDiff line numberDiff line change
@@ -843,10 +843,6 @@ func buildDepositRequestKey(
843843
return sha256.Sum256(append(fundingTxHash[:], buffer...))
844844
}
845845

846-
func (lc *localChain) IsWalletRegistered(EcdsaWalletID [32]byte) (bool, error) {
847-
panic("unsupported")
848-
}
849-
850846
func (lc *localChain) CalculateWalletID(
851847
walletPublicKey *ecdsa.PublicKey,
852848
) ([32]byte, error) {
@@ -896,6 +892,23 @@ func (lc *localChain) GetWallet(walletPublicKeyHash [20]byte) (
896892
return walletChainData, nil
897893
}
898894

895+
func (lc *localChain) IsWalletRegistered(EcdsaWalletID [32]byte) (bool, error) {
896+
lc.walletsMutex.Lock()
897+
defer lc.walletsMutex.Unlock()
898+
899+
for _, walletData := range lc.wallets {
900+
if EcdsaWalletID == walletData.EcdsaWalletID {
901+
if walletData.State == StateClosed ||
902+
walletData.State == StateTerminated {
903+
return false, nil
904+
}
905+
return true, nil
906+
}
907+
}
908+
909+
return false, fmt.Errorf("wallet not found")
910+
}
911+
899912
func (lc *localChain) setWallet(
900913
walletPublicKeyHash [20]byte,
901914
walletChainData *WalletChainData,

pkg/tbtc/inactivity_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,16 @@ func setupInactivityClaimExecutorScenario(t *testing.T) (
157157
keyStorePersistence := createMockKeyStorePersistence(t, signers...)
158158

159159
walletPublicKeyHash := bitcoin.PublicKeyHash(signers[0].wallet.publicKey)
160-
ecdsaWalletID := [32]byte{1, 2, 3}
160+
walletID, err := localChain.CalculateWalletID(signers[0].wallet.publicKey)
161+
if err != nil {
162+
t.Fatal(err)
163+
}
161164

162165
localChain.setWallet(
163166
walletPublicKeyHash,
164167
&WalletChainData{
165-
EcdsaWalletID: ecdsaWalletID,
168+
EcdsaWalletID: walletID,
169+
State: StateLive,
166170
},
167171
)
168172

@@ -191,7 +195,7 @@ func setupInactivityClaimExecutorScenario(t *testing.T) (
191195
t.Fatal("node is supposed to control wallet signers")
192196
}
193197

194-
return executor, ecdsaWalletID, localChain
198+
return executor, walletID, localChain
195199
}
196200

197201
func TestSignClaim_SigningSuccessful(t *testing.T) {

pkg/tbtc/node_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/keep-network/keep-common/pkg/persistence"
1313
"github.com/keep-network/keep-core/internal/testutils"
14+
"github.com/keep-network/keep-core/pkg/bitcoin"
1415
"github.com/keep-network/keep-core/pkg/chain"
1516
"github.com/keep-network/keep-core/pkg/generator"
1617
"github.com/keep-network/keep-core/pkg/internal/tecdsatest"
@@ -31,6 +32,20 @@ func TestNode_GetSigningExecutor(t *testing.T) {
3132

3233
signer := createMockSigner(t)
3334

35+
walletPublicKeyHash := bitcoin.PublicKeyHash(signer.wallet.publicKey)
36+
walletID, err := localChain.CalculateWalletID(signer.wallet.publicKey)
37+
if err != nil {
38+
t.Fatal(err)
39+
}
40+
41+
localChain.setWallet(
42+
walletPublicKeyHash,
43+
&WalletChainData{
44+
EcdsaWalletID: walletID,
45+
State: StateLive,
46+
},
47+
)
48+
3449
// Populate the mock keystore with the mock signer's data. This is
3550
// required to make the node controlling the signer's wallet.
3651
keyStorePersistence := createMockKeyStorePersistence(t, signer)
@@ -149,6 +164,20 @@ func TestNode_GetCoordinationExecutor(t *testing.T) {
149164

150165
signer := createMockSigner(t)
151166

167+
walletPublicKeyHash := bitcoin.PublicKeyHash(signer.wallet.publicKey)
168+
walletID, err := localChain.CalculateWalletID(signer.wallet.publicKey)
169+
if err != nil {
170+
t.Fatal(err)
171+
}
172+
173+
localChain.setWallet(
174+
walletPublicKeyHash,
175+
&WalletChainData{
176+
EcdsaWalletID: walletID,
177+
State: StateLive,
178+
},
179+
)
180+
152181
// Populate the mock keystore with the mock signer's data. This is
153182
// required to make the node controlling the signer's wallet.
154183
keyStorePersistence := createMockKeyStorePersistence(t, signer)
@@ -272,6 +301,20 @@ func TestNode_RunCoordinationLayer(t *testing.T) {
272301

273302
signer := createMockSigner(t)
274303

304+
walletPublicKeyHash := bitcoin.PublicKeyHash(signer.wallet.publicKey)
305+
walletID, err := localChain.CalculateWalletID(signer.wallet.publicKey)
306+
if err != nil {
307+
t.Fatal(err)
308+
}
309+
310+
localChain.setWallet(
311+
walletPublicKeyHash,
312+
&WalletChainData{
313+
EcdsaWalletID: walletID,
314+
State: StateLive,
315+
},
316+
)
317+
275318
// Populate the mock keystore with the mock signer's data. This is
276319
// required to make the node controlling the signer's wallet.
277320
keyStorePersistence := createMockKeyStorePersistence(t, signer)

pkg/tbtc/signing_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/keep-network/keep-core/internal/testutils"
11+
"github.com/keep-network/keep-core/pkg/bitcoin"
1112
"github.com/keep-network/keep-core/pkg/chain"
1213
"github.com/keep-network/keep-core/pkg/chain/local_v1"
1314
"github.com/keep-network/keep-core/pkg/generator"
@@ -159,6 +160,20 @@ func setupSigningExecutor(t *testing.T) *signingExecutor {
159160
}
160161
}
161162

163+
walletPublicKeyHash := bitcoin.PublicKeyHash(signers[0].wallet.publicKey)
164+
walletID, err := localChain.CalculateWalletID(signers[0].wallet.publicKey)
165+
if err != nil {
166+
t.Fatal(err)
167+
}
168+
169+
localChain.setWallet(
170+
walletPublicKeyHash,
171+
&WalletChainData{
172+
EcdsaWalletID: walletID,
173+
State: StateLive,
174+
},
175+
)
176+
162177
keyStorePersistence := createMockKeyStorePersistence(t, signers...)
163178

164179
node, err := newNode(

0 commit comments

Comments
 (0)