MCPcopy Create free account
hub / github.com/chain/Core / TestGenerateBlock

Function TestGenerateBlock

protocol/block_test.go:127–194  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

125}
126
127func TestGenerateBlock(t *testing.T) {
128 ctx := context.Background()
129 now := time.Unix(233400000, 0)
130 c, b1 := newTestChain(t, now)
131
132 initialBlockHash := b1.Hash()
133 assetID := bc.ComputeAssetID(nil, &initialBlockHash, 1, &bc.EmptyStringHash)
134
135 txs := []*legacy.Tx{
136 legacy.NewTx(legacy.TxData{
137 Version: 1,
138 MinTime: 233400000000,
139 MaxTime: 233400000001,
140 Inputs: []*legacy.TxInput{
141 legacy.NewIssuanceInput([]byte{1}, 50, nil, initialBlockHash, nil, [][]byte{
142 nil,
143 mustDecodeHex("30450221009037e1d39b7d59d24eba8012baddd5f4ab886a51b46f52b7c479ddfa55eeb5c5022076008409243475b25dfba6db85e15cf3d74561a147375941e4830baa69769b5101"),
144 mustDecodeHex("51210210b002870438af79b829bc22c4505e14779ef0080c411ad497d7a0846ee0af6f51ae")}, nil),
145 },
146 Outputs: []*legacy.TxOutput{
147 legacy.NewTxOutput(assetID, 50, mustDecodeHex("a9145881cd104f8d64635751ac0f3c0decf9150c110687"), nil),
148 },
149 }),
150 legacy.NewTx(legacy.TxData{
151 Version: 1,
152 MinTime: 233400000000,
153 MaxTime: 233400000001,
154 Inputs: []*legacy.TxInput{
155 legacy.NewIssuanceInput([]byte{2}, 50, nil, initialBlockHash, nil, [][]byte{
156 nil,
157 mustDecodeHex("3045022100f3bcffcfd6a1ce9542b653500386cd0ee7b9c86c59390ca0fc0238c0ebe3f1d6022065ac468a51a016842660c3a616c99a9aa5109a3bad1877ba3e0f010f3972472e01"),
158 mustDecodeHex("51210210b002870438af79b829bc22c4505e14779ef0080c411ad497d7a0846ee0af6f51ae"),
159 }, nil),
160 },
161 Outputs: []*legacy.TxOutput{
162 legacy.NewTxOutput(assetID, 50, mustDecodeHex("a914c171e443e05b953baa7b7d834028ed91e47b4d0b87"), nil),
163 },
164 }),
165 }
166
167 got, _, err := c.GenerateBlock(ctx, b1, state.Empty(), now, txs)
168 if err != nil {
169 t.Fatalf("err got = %v want nil", err)
170 }
171
172 // TODO(bobg): verify these hashes are correct
173 wantTxRoot := mustDecodeHash("ab5f5f111beb1e6b49da8334360589c7da3aac1cdd61067ea9a55bec47cb745c")
174 wantAssetsRoot := mustDecodeHash("a31a9b5f71a6d6fa0c87361db4a98c9a82f603f9d9ff584f6613b9d56ccf5ebd")
175
176 want := &legacy.Block{
177 BlockHeader: legacy.BlockHeader{
178 Version: 1,
179 Height: 2,
180 PreviousBlockHash: b1.Hash(),
181 TimestampMS: bc.Millis(now),
182 BlockCommitment: legacy.BlockCommitment{
183 TransactionsMerkleRoot: wantTxRoot,
184 AssetsMerkleRoot: wantAssetsRoot,

Callers

nothing calls this directly

Calls 6

newTestChainFunction · 0.85
ComputeAssetIDMethod · 0.80
GenerateBlockMethod · 0.80
mustDecodeHexFunction · 0.70
mustDecodeHashFunction · 0.70
HashMethod · 0.45

Tested by

no test coverage detected