forked from ten-protocol/go-ten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobscuroscan_test.go
47 lines (36 loc) · 1.35 KB
/
obscuroscan_test.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
45
46
47
package obscuroscan
import (
"encoding/base64"
"encoding/json"
"testing"
"github.com/obscuronet/go-obscuro/go/enclave/core"
"github.com/obscuronet/go-obscuro/go/enclave/crypto"
"github.com/obscuronet/go-obscuro/integration/datagenerator"
"github.com/obscuronet/go-obscuro/go/common"
)
func TestCanDecryptTxBlob(t *testing.T) {
txs := []*common.L2Tx{datagenerator.CreateL2Tx(), datagenerator.CreateL2Tx()}
txsJSONBytes, err := decryptTxBlob(generateEncryptedTxBlob(txs))
if err != nil {
t.Fatalf("transaction blob decryption failed. Cause: %s", err)
}
expectedTxsJSONBytes, err := json.Marshal(txs)
if err != nil {
t.Fatalf("marshalling transactions to JSON failed. Cause: %s", err)
}
if string(expectedTxsJSONBytes) != string(txsJSONBytes) {
t.Fatalf("expected %s, got %s", string(expectedTxsJSONBytes), string(txsJSONBytes))
}
}
func TestThrowsIfEncryptedRollupIsInvalid(t *testing.T) {
_, err := decryptTxBlob([]byte("invalid_tx_blob"))
if err == nil {
t.Fatal("did not error on invalid transaction blob")
}
}
// Generates an encrypted transaction blob in Base64 encoding.
func generateEncryptedTxBlob(txs []*common.L2Tx) []byte {
rollup := core.Rollup{Header: &common.Header{}, Transactions: txs}
txBlob := rollup.ToExtRollup(crypto.NewTransactionBlobCryptoImpl(nil)).EncryptedTxBlob
return []byte(base64.StdEncoding.EncodeToString(txBlob))
}