-
Notifications
You must be signed in to change notification settings - Fork 48
/
util.go
44 lines (34 loc) · 1.01 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT License was not distributed with this
// file, you can obtain one at https://opensource.org/licenses/MIT.
//
// Copyright (c) DUSK NETWORK. All rights reserved.
package helper
import (
"bytes"
"crypto/rand"
"testing"
"github.com/dusk-network/dusk-blockchain/pkg/core/data/ipc/transactions"
assert "github.com/stretchr/testify/require"
)
// TxsToBuffer converts a slice of transactions to a bytes.Buffer.
func TxsToBuffer(t *testing.T, txs []transactions.ContractCall) *bytes.Buffer {
assert := assert.New(t)
whole := new(bytes.Buffer)
for _, tx := range txs {
buf := new(bytes.Buffer)
assert.NoError(transactions.Marshal(buf, tx))
_, err := whole.ReadFrom(buf)
assert.NoError(err)
}
return whole
}
// RandomSlice returns a random slice of size `size`.
func RandomSlice(size uint32) []byte {
randSlice := make([]byte, size)
_, err := rand.Read(randSlice)
if err != nil {
panic(err)
}
return randSlice
}