lotus/chain/vm/runtime_test.go

68 lines
1.4 KiB
Go
Raw Normal View History

2020-04-28 13:21:56 +00:00
package vm
import (
"io"
"testing"
cbor "github.com/ipfs/go-ipld-cbor"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
2020-09-07 03:49:10 +00:00
"github.com/filecoin-project/go-state-types/exitcode"
2020-04-28 13:21:56 +00:00
"github.com/filecoin-project/lotus/chain/actors/aerrors"
)
2020-04-29 18:06:05 +00:00
type NotAVeryGoodMarshaler struct{}
2020-04-28 13:21:56 +00:00
func (*NotAVeryGoodMarshaler) MarshalCBOR(writer io.Writer) error {
return xerrors.Errorf("no")
}
var _ cbg.CBORMarshaler = &NotAVeryGoodMarshaler{}
func TestRuntimePutErrors(t *testing.T) {
defer func() {
err := recover()
if err == nil {
t.Fatal("expected non-nil recovery")
}
aerr := err.(aerrors.ActorError)
if aerr.IsFatal() {
t.Fatal("expected non-fatal actor error")
}
if aerr.RetCode() != exitcode.ErrSerialization {
t.Fatal("expected serialization error")
}
}()
rt := Runtime{
cst: cbor.NewCborStore(nil),
}
rt.StorePut(&NotAVeryGoodMarshaler{})
2020-04-28 13:21:56 +00:00
t.Error("expected panic")
}
2020-10-07 14:52:03 +00:00
func BenchmarkRuntime_CreateRuntimeChargeGas_TracingDisabled(b *testing.B) {
var (
cst = cbor.NewCborStore(nil)
gch = newGasCharge("foo", 1000, 1000)
)
b.ResetTimer()
EnableGasTracing = false
noop := func() bool { return EnableGasTracing }
for n := 0; n < b.N; n++ {
// flip the value and access it to make sure
// the compiler doesn't optimize away
EnableGasTracing = true
_ = noop()
EnableGasTracing = false
_ = (&Runtime{cst: cst}).chargeGasInternal(gch, 0)
}
}