MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / generateRandomBlock

Function generateRandomBlock

types/xxx_test.go:89–124  ·  view source on GitHub ↗
(parent hash.Hash, isGenesis bool)

Source from the content-addressed store, hash-verified

87}
88
89func generateRandomBlock(parent hash.Hash, isGenesis bool) (b *BPBlock, err error) {
90 // Generate key pair
91 priv, _, err := asymmetric.GenSecp256k1KeyPair()
92
93 if err != nil {
94 return
95 }
96
97 h := hash.Hash{}
98 rand.Read(h[:])
99
100 b = &BPBlock{
101 SignedHeader: BPSignedHeader{
102 BPHeader: BPHeader{
103 Version: 0x01000000,
104 Producer: proto.AccountAddress(h),
105 ParentHash: parent,
106 Timestamp: time.Now().UTC(),
107 },
108 },
109 }
110
111 for i, n := 0, rand.Intn(10)+10; i < n; i++ {
112 tb, err := generateRandomTransfer()
113 if err != nil {
114 return nil, err
115
116 }
117 b.Transactions = append(b.Transactions, tb)
118
119 }
120
121 err = b.PackAndSignBlock(priv)
122
123 return
124}
125
126func randBytes(n int) (b []byte) {
127 b = make([]byte, n)

Calls 5

GenSecp256k1KeyPairFunction · 0.92
AccountAddressTypeAlias · 0.92
generateRandomTransferFunction · 0.85
ReadMethod · 0.65
PackAndSignBlockMethod · 0.45

Tested by

no test coverage detected