diff --git a/pkg/receipts/buffer.go b/pkg/receipts/buffer.go index f43c560..1917962 100644 --- a/pkg/receipts/buffer.go +++ b/pkg/receipts/buffer.go @@ -20,6 +20,7 @@ func (b *Buffer) Emit(wallet common.Address, amount decimal.Decimal, txHash stri } func (b *Buffer) Finalize() []byte { + b.init() b.csv.Flush() return b.buf.Bytes() } diff --git a/pkg/receipts/buffer_test.go b/pkg/receipts/buffer_test.go index 32b5b92..7481e43 100644 --- a/pkg/receipts/buffer_test.go +++ b/pkg/receipts/buffer_test.go @@ -16,14 +16,23 @@ func TestBuffer(t *testing.T) { address2 := common.BytesToAddress(bytes.Repeat([]byte{2}, common.AddressLength)) address3 := common.BytesToAddress(bytes.Repeat([]byte{3}, common.AddressLength)) - var b receipts.Buffer - b.Emit(address1, decimal.NewFromInt(1), "hash1", payer.Eth) - b.Emit(address2, decimal.NewFromInt(2), "hash2", payer.Eth) - b.Emit(address3, decimal.NewFromInt(3), "hash3", payer.ZkSyncEra) - receipts := b.Finalize() - require.Equal(t, `wallet,amount,txhash,mechanism + t.Run("without receipts", func(t *testing.T) { + var b receipts.Buffer + receipts := b.Finalize() + require.Equal(t, `wallet,amount,txhash,mechanism +`, string(receipts)) + }) + + t.Run("with receipts", func(t *testing.T) { + var b receipts.Buffer + b.Emit(address1, decimal.NewFromInt(1), "hash1", payer.Eth) + b.Emit(address2, decimal.NewFromInt(2), "hash2", payer.Eth) + b.Emit(address3, decimal.NewFromInt(3), "hash3", payer.ZkSyncEra) + receipts := b.Finalize() + require.Equal(t, `wallet,amount,txhash,mechanism 0x0101010101010101010101010101010101010101,1,hash1,eth 0x0202020202020202020202020202020202020202,2,hash2,eth 0x0303030303030303030303030303030303030303,3,hash3,zksync-era `, string(receipts)) + }) }