MCPcopy Create free account
hub / github.com/chain/txvm / TestBlockOnly

Function TestBlockOnly

protocol/validation/validation_test.go:145–203  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

143}
144
145func TestBlockOnly(t *testing.T) {
146 cases := []struct {
147 tx *bc.Tx
148 wantErr error
149 }{{
150 tx: &bc.Tx{
151 RawTx: bc.RawTx{
152 Version: 3,
153 Runlimit: 2000,
154 },
155 ID: bc.NewHash([32]byte{1}),
156 },
157 wantErr: nil,
158 }, {
159 tx: &bc.Tx{
160 RawTx: bc.RawTx{
161 Version: 2,
162 Runlimit: 2000,
163 },
164 ID: bc.NewHash([32]byte{1}),
165 },
166 wantErr: errTxVersion,
167 }, {
168 tx: &bc.Tx{
169 RawTx: bc.RawTx{
170 Version: 3,
171 Runlimit: 5001,
172 },
173 ID: bc.NewHash([32]byte{1}),
174 },
175 wantErr: errRunlimit,
176 }, {
177 tx: &bc.Tx{
178 RawTx: bc.RawTx{
179 Version: 3,
180 Runlimit: 2000,
181 },
182 ID: bc.NewHash([32]byte{2}),
183 },
184 wantErr: errMismatchedMerkleRoot,
185 }}
186
187 txRoot := bc.TxMerkleRoot([]*bc.Tx{cases[0].tx})
188 block := &bc.UnsignedBlock{
189 BlockHeader: &bc.BlockHeader{
190 Version: 3,
191 Runlimit: 5000,
192 TransactionsRoot: &txRoot,
193 },
194 }
195
196 for i, c := range cases {
197 block.Transactions = []*bc.Tx{c.tx}
198 gotErr := BlockOnly(block)
199 if errors.Root(gotErr) != c.wantErr {
200 t.Errorf("BlockOnly(%d) = %v want %v", i, gotErr, c.wantErr)
201 }
202 }

Callers

nothing calls this directly

Calls 4

NewHashFunction · 0.92
TxMerkleRootFunction · 0.92
RootFunction · 0.92
BlockOnlyFunction · 0.85

Tested by

no test coverage detected