Skip to content

Commit 918b5f1

Browse files
authored
test(chainsync): Use renamed and fixed-size Credential struct (#395)
Signed-off-by: Akhil Repala <[email protected]>
1 parent 98db209 commit 918b5f1

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

filter/chainsync/chainsync_test.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package chainsync
1515

1616
import (
17+
"bytes"
1718
"encoding/hex"
1819
"testing"
1920
"time"
@@ -23,6 +24,7 @@ import (
2324
"github.com/blinklabs-io/gouroboros/cbor"
2425
"github.com/blinklabs-io/gouroboros/ledger"
2526
"github.com/blinklabs-io/gouroboros/ledger/common"
27+
"github.com/btcsuite/btcd/btcutil/bech32"
2628
"github.com/stretchr/testify/assert"
2729
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
2830
)
@@ -205,16 +207,16 @@ type mockStakeDeregistrationCert struct {
205207

206208
func (m *mockStakeDeregistrationCert) Cbor() []byte { return m.cborData }
207209

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,
214216
}
215217
}
216218

217-
func mockStakeCredentialPtr(credType uint, hashBytes []byte) *common.StakeCredential {
219+
func mockStakeCredentialPtr(credType uint, hashBytes []byte) *common.Credential {
218220
cred := mockStakeCredentialValue(credType, hashBytes)
219221
return &cred
220222
}
@@ -224,6 +226,11 @@ func mockAddress(addrStr string) common.Address {
224226
}
225227

226228
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+
227234
tests := []struct {
228235
name string
229236
filterAddress string
@@ -240,19 +247,19 @@ func TestFilterByAddress(t *testing.T) {
240247

241248
{
242249
name: "StakeDelegationCertificate match",
243-
filterAddress: "stake1276l2v4nvtm6mpr7s6cu3ezneh6vrunlw0jahq9fxy6v6e37p04",
250+
filterAddress: testStakeAddress,
244251
outputAddr: mockAddress("addr_doesnt_match"),
245252
cert: &common.StakeDelegationCertificate{
246-
StakeCredential: mockStakeCredentialPtr(0, []byte{1, 2, 3}),
253+
StakeCredential: &cred,
247254
},
248255
shouldMatch: true,
249256
},
250257
{
251258
name: "StakeDeregistrationCertificate match",
252-
filterAddress: "stake1276l2v4nvtm6mpr7s6cu3ezneh6vrunlw0jahq9fxy6v6e37p04",
259+
filterAddress: testStakeAddress,
253260
outputAddr: mockAddress("addr_doesnt_match"),
254261
cert: &common.StakeDeregistrationCertificate{
255-
StakeDeregistration: mockStakeCredentialValue(0, []byte{1, 2, 3}),
262+
StakeDeregistration: cred,
256263
},
257264
shouldMatch: true,
258265
},

0 commit comments

Comments
 (0)