github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/evm/emulator/state/code_test.go (about) 1 package state_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 "github.com/onflow/flow-go/fvm/evm/emulator/state" 9 ) 10 11 func TestCodeContainer(t *testing.T) { 12 code := []byte("some code") 13 14 // test construction 15 cc := state.NewCodeContainer(code) 16 require.Equal(t, uint64(1), cc.RefCount()) 17 require.Equal(t, code, cc.Code()) 18 19 // test increment 20 cc.IncRefCount() 21 require.Equal(t, uint64(2), cc.RefCount()) 22 23 // test encoding 24 encoded := cc.Encode() 25 cc, err := state.CodeContainerFromEncoded(encoded) 26 require.NoError(t, err) 27 require.Equal(t, uint64(2), cc.RefCount()) 28 require.Equal(t, code, cc.Code()) 29 30 // test decrement 31 require.Equal(t, false, cc.DecRefCount()) 32 require.Equal(t, uint64(1), cc.RefCount()) 33 require.Equal(t, true, cc.DecRefCount()) 34 require.Equal(t, uint64(0), cc.RefCount()) 35 }