14
14
package chainsync
15
15
16
16
import (
17
+ "bytes"
17
18
"encoding/hex"
18
19
"testing"
19
20
"time"
@@ -23,6 +24,7 @@ import (
23
24
"github.com/blinklabs-io/gouroboros/cbor"
24
25
"github.com/blinklabs-io/gouroboros/ledger"
25
26
"github.com/blinklabs-io/gouroboros/ledger/common"
27
+ "github.com/btcsuite/btcd/btcutil/bech32"
26
28
"github.com/stretchr/testify/assert"
27
29
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
28
30
)
@@ -205,16 +207,16 @@ type mockStakeDeregistrationCert struct {
205
207
206
208
func (m * mockStakeDeregistrationCert ) Cbor () []byte { return m .cborData }
207
209
208
- func mockStakeCredentialValue (credType uint , hashBytes []byte ) common.StakeCredential {
209
- return common.StakeCredential {
210
- StructAsArray : cbor. StructAsArray {},
211
- DecodeStoreCbor : cbor. DecodeStoreCbor {},
212
- CredType : credType ,
213
- Credential : hashBytes ,
210
+ func mockStakeCredentialValue (credType uint , hashBytes []byte ) common.Credential {
211
+ var credHash common.CredentialHash
212
+ copy ( credHash [:], hashBytes )
213
+ return common. Credential {
214
+ CredType : credType ,
215
+ Credential : credHash ,
214
216
}
215
217
}
216
218
217
- func mockStakeCredentialPtr (credType uint , hashBytes []byte ) * common.StakeCredential {
219
+ func mockStakeCredentialPtr (credType uint , hashBytes []byte ) * common.Credential {
218
220
cred := mockStakeCredentialValue (credType , hashBytes )
219
221
return & cred
220
222
}
@@ -224,6 +226,11 @@ func mockAddress(addrStr string) common.Address {
224
226
}
225
227
226
228
func TestFilterByAddress (t * testing.T ) {
229
+ cred := mockStakeCredentialValue (0 , bytes .Repeat ([]byte {1 }, 28 ))
230
+ credHash := cred .Hash ()
231
+ convData , _ := bech32 .ConvertBits (credHash [:], 8 , 5 , true )
232
+ testStakeAddress , _ := bech32 .Encode ("stake" , convData )
233
+
227
234
tests := []struct {
228
235
name string
229
236
filterAddress string
@@ -240,19 +247,19 @@ func TestFilterByAddress(t *testing.T) {
240
247
241
248
{
242
249
name : "StakeDelegationCertificate match" ,
243
- filterAddress : "stake1276l2v4nvtm6mpr7s6cu3ezneh6vrunlw0jahq9fxy6v6e37p04" ,
250
+ filterAddress : testStakeAddress ,
244
251
outputAddr : mockAddress ("addr_doesnt_match" ),
245
252
cert : & common.StakeDelegationCertificate {
246
- StakeCredential : mockStakeCredentialPtr ( 0 , [] byte { 1 , 2 , 3 }) ,
253
+ StakeCredential : & cred ,
247
254
},
248
255
shouldMatch : true ,
249
256
},
250
257
{
251
258
name : "StakeDeregistrationCertificate match" ,
252
- filterAddress : "stake1276l2v4nvtm6mpr7s6cu3ezneh6vrunlw0jahq9fxy6v6e37p04" ,
259
+ filterAddress : testStakeAddress ,
253
260
outputAddr : mockAddress ("addr_doesnt_match" ),
254
261
cert : & common.StakeDeregistrationCertificate {
255
- StakeDeregistration : mockStakeCredentialValue ( 0 , [] byte { 1 , 2 , 3 }) ,
262
+ StakeDeregistration : cred ,
256
263
},
257
264
shouldMatch : true ,
258
265
},
0 commit comments