OSDN Git Service

new repo
[bytom/vapor.git] / protocol / bc / asset_test.go
1 package bc
2
3 import (
4         "testing"
5
6         "golang.org/x/crypto/sha3"
7 )
8
9 func TestComputeAssetID(t *testing.T) {
10         issuanceScript := []byte{1}
11         assetID := ComputeAssetID(issuanceScript, 1, &EmptyStringHash)
12
13         unhashed := append([]byte{})
14         unhashed = append(unhashed, []byte{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}...) // vmVersion
15         unhashed = append(unhashed, 0x01)                                                      // length of issuanceScript
16         unhashed = append(unhashed, issuanceScript...)
17         unhashed = append(unhashed, EmptyStringHash.Bytes()...)
18
19         if want := NewAssetID(sha3.Sum256(unhashed)); assetID != want {
20                 t.Errorf("asset id = %x want %x", assetID.Bytes(), want.Bytes())
21         }
22 }
23
24 var assetIDSink AssetID
25
26 func BenchmarkComputeAssetID(b *testing.B) {
27         var (
28                 issuanceScript = []byte{5}
29         )
30
31         for i := 0; i < b.N; i++ {
32                 assetIDSink = ComputeAssetID(issuanceScript, 1, &EmptyStringHash)
33         }
34 }