github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/swarm/storage/feed/update_test.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 19:16:45</date>
    10  //</624450119692980224>
    11  
    12  
    13  package feed
    14  
    15  import (
    16  	"testing"
    17  )
    18  
    19  func getTestFeedUpdate() *Update {
    20  	return &Update{
    21  		ID:   *getTestID(),
    22  		data: []byte("El que lee mucho y anda mucho, ve mucho y sabe mucho"),
    23  	}
    24  }
    25  
    26  func TestUpdateSerializer(t *testing.T) {
    27  	testBinarySerializerRecovery(t, getTestFeedUpdate(), "0x0000000000000000776f726c64206e657773207265706f72742c20657665727920686f7572000000876a8936a7cd0b79ef0735ad0896c1afe278781ce803000000000019456c20717565206c6565206d7563686f207920616e6461206d7563686f2c207665206d7563686f20792073616265206d7563686f")
    28  }
    29  
    30  func TestUpdateLengthCheck(t *testing.T) {
    31  	testBinarySerializerLengthCheck(t, getTestFeedUpdate())
    32  //如果更新太大,则测试失败
    33  	update := getTestFeedUpdate()
    34  	update.data = make([]byte, MaxUpdateDataLength+100)
    35  	serialized := make([]byte, update.binaryLength())
    36  	if err := update.binaryPut(serialized); err == nil {
    37  		t.Fatal("Expected update.binaryPut to fail since update is too big")
    38  	}
    39  
    40  //如果数据为空或为零,则测试失败
    41  	update.data = nil
    42  	serialized = make([]byte, update.binaryLength())
    43  	if err := update.binaryPut(serialized); err == nil {
    44  		t.Fatal("Expected update.binaryPut to fail since data is empty")
    45  	}
    46  }
    47