diff --git a/pkg/smartcontract/call_flags.go b/pkg/smartcontract/call_flags.go index 94234a75d..e8a070eaf 100644 --- a/pkg/smartcontract/call_flags.go +++ b/pkg/smartcontract/call_flags.go @@ -13,3 +13,8 @@ const ( ReadOnly = AllowStates | AllowCall | AllowNotify All = ReadOnly | AllowModifyStates ) + +// Has returns true iff all bits set in cf are also set in f. +func (f CallFlag) Has(cf CallFlag) bool { + return f&cf == cf +} diff --git a/pkg/smartcontract/call_flags_test.go b/pkg/smartcontract/call_flags_test.go new file mode 100644 index 000000000..f50f12ce5 --- /dev/null +++ b/pkg/smartcontract/call_flags_test.go @@ -0,0 +1,14 @@ +package smartcontract + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestCallFlag_Has(t *testing.T) { + require.True(t, AllowCall.Has(AllowCall)) + require.True(t, (AllowCall | AllowNotify).Has(AllowCall)) + require.False(t, (AllowCall).Has(AllowCall|AllowNotify)) + require.True(t, All.Has(ReadOnly)) +}