Skip to content

Commit

Permalink
test: fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Sep 1, 2023
1 parent efb75b3 commit 09b46ba
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
16 changes: 8 additions & 8 deletions store/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ func (m *MockStore) BlockHeight(hash hash.Hash) uint32 {
}

func (m *MockStore) PublicKey(addr crypto.Address) (*bls.PublicKey, error) {
for _, block := range m.Blocks {
for _, trx := range block.Transactions() {
if trx.Payload().Signer() == addr {
return trx.PublicKey().(*bls.PublicKey), nil
}
}
}
return nil, nil
for _, block := range m.Blocks {
for _, trx := range block.Transactions() {
if trx.Payload().Signer() == addr {
return trx.PublicKey().(*bls.PublicKey), nil
}
}
}
return nil, ErrNotFound
}

func (m *MockStore) Transaction(id tx.ID) (*CommittedTx, error) {
Expand Down
4 changes: 2 additions & 2 deletions types/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@ func TestBlockHash(t *testing.T) {
hashData = append(hashData, util.Int32ToSlice(int32(b.Transactions().Len()))...)

expected1 := hash.CalcHash(hashData)
expected2, _ := hash.FromString("26f911e9c72a0619c010b396f83b09edef70e56bd47c121699b12520ba5f02ed")
expected2, _ := hash.FromString("2f9e14e66a6d2e3695dad65d273414e5aec92949c7f64a5b18fc6a1bf8006db5")
assert.Equal(t, b.Hash(), expected1)
assert.Equal(t, b.Hash(), expected2)
assert.Equal(t, b.Stamp(), hash.Stamp{0x26, 0xf9, 0x11, 0xe9})
assert.Equal(t, b.Stamp(), hash.Stamp{0x2f, 0x9e, 0x14, 0xe6})
}

func TestMakeBlock(t *testing.T) {
Expand Down
48 changes: 24 additions & 24 deletions types/tx/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,30 +330,30 @@ func TestInvalidSignature(t *testing.T) {
}

func TestSignBytes(t *testing.T) {
d, _ := hex.DecodeString(
"00" + // Flags
"01" + // Version
"a1b2c3d4" + // Stamp
"01" + // Sequence
"01" + // Fee
"00" + // Memo
"01" + // PayloadType
"013333333333333333333333333333333333333333" + // Sender
"012222222222222222222222222222222222222222" + // Receiver
"01" + // Amount
"b53d79e156e9417e010fa21f2b2a96bee6be46fcd233295d2f697cdb9e782b6112ac01c80d0d9d64c2320664c77fa2a6" + // Signature
"8d82fa4fcac04a3b565267685e90db1b01420285d2f8295683c138c092c209479983ba1591370778846681b7b558e061" + // PublicKey
"1776208c0718006311c84b4a113335c70d1f5c7c5dd93a5625c4af51c48847abd0b590c055306162d2a03ca1cbf7bcc1")

h, _ := hash.FromString("223f5eec2145d3592ffad4e079a07ffe89044e930dc03b5d47f2ad829d2a09c6")
trx, err := tx.FromBytes(d)
assert.NoError(t, err)
assert.Equal(t, trx.SerializeSize(), len(d))

sb := d[2 : len(d)-bls.PublicKeySize-bls.SignatureSize]
assert.Equal(t, sb, trx.SignBytes())
assert.Equal(t, trx.ID(), h)
assert.Equal(t, trx.ID(), hash.CalcHash(sb))
d, _ := hex.DecodeString(
"00" + // Flags
"01" + // Version
"a1b2c3d4" + // Stamp
"01" + // Sequence
"01" + // Fee
"00" + // Memo
"01" + // PayloadType
"013333333333333333333333333333333333333333" + // Sender
"012222222222222222222222222222222222222222" + // Receiver
"01" + // Amount
"b53d79e156e9417e010fa21f2b2a96bee6be46fcd233295d2f697cdb9e782b6112ac01c80d0d9d64c2320664c77fa2a6" + // Signature
"8d82fa4fcac04a3b565267685e90db1b01420285d2f8295683c138c092c209479983ba1591370778846681b7b558e061" + // PublicKey
"1776208c0718006311c84b4a113335c70d1f5c7c5dd93a5625c4af51c48847abd0b590c055306162d2a03ca1cbf7bcc1")

h, _ := hash.FromString("223f5eec2145d3592ffad4e079a07ffe89044e930dc03b5d47f2ad829d2a09c6")
trx, err := tx.FromBytes(d)
assert.NoError(t, err)
assert.Equal(t, trx.SerializeSize(), len(d))

sb := d[2 : len(d)-bls.PublicKeySize-bls.SignatureSize]
assert.Equal(t, sb, trx.SignBytes())
assert.Equal(t, trx.ID(), h)
assert.Equal(t, trx.ID(), hash.CalcHash(sb))
}

func TestStripPublicKey(t *testing.T) {
Expand Down

0 comments on commit 09b46ba

Please sign in to comment.