smartcontract: add CallFlag.Has() helper

This commit is contained in:
Evgenii Stratonikov 2020-06-10 15:50:51 +03:00
parent ebbf0321b2
commit 532262827d
2 changed files with 19 additions and 0 deletions

View file

@ -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
}

View file

@ -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))
}