github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/whisper/whisperv6/envelope_test.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  //
    10  //
    11  //
    12  //
    13  //
    14  //
    15  //
    16  //
    17  //
    18  //
    19  //
    20  //
    21  //
    22  //
    23  //
    24  
    25  //
    26  
    27  package whisperv6
    28  
    29  import (
    30  	mrand "math/rand"
    31  	"testing"
    32  
    33  	"github.com/ethereum/go-ethereum/crypto"
    34  )
    35  
    36  func TestEnvelopeOpenAcceptsOnlyOneKeyTypeInFilter(t *testing.T) {
    37  	symKey := make([]byte, aesKeyLength)
    38  	mrand.Read(symKey)
    39  
    40  	asymKey, err := crypto.GenerateKey()
    41  	if err != nil {
    42  		t.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
    43  	}
    44  
    45  	params := MessageParams{
    46  		PoW:      0.01,
    47  		WorkTime: 1,
    48  		TTL:      uint32(mrand.Intn(1024)),
    49  		Payload:  make([]byte, 50),
    50  		KeySym:   symKey,
    51  		Dst:      nil,
    52  	}
    53  
    54  	mrand.Read(params.Payload)
    55  
    56  	msg, err := NewSentMessage(&params)
    57  	if err != nil {
    58  		t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
    59  	}
    60  
    61  	e, err := msg.Wrap(&params)
    62  	if err != nil {
    63  		t.Fatalf("Failed to Wrap the message in an envelope with seed %d: %s", seed, err)
    64  	}
    65  
    66  	f := Filter{KeySym: symKey, KeyAsym: asymKey}
    67  
    68  	decrypted := e.Open(&f)
    69  	if decrypted != nil {
    70  		t.Fatalf("Managed to decrypt a message with an invalid filter, seed %d", seed)
    71  	}
    72  }