diff --git a/go/consensus/tendermint/apps/staking/transactions_test.go b/go/consensus/tendermint/apps/staking/transactions_test.go new file mode 100644 index 00000000000..4261c193232 --- /dev/null +++ b/go/consensus/tendermint/apps/staking/transactions_test.go @@ -0,0 +1,65 @@ +package staking + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/oasislabs/oasis-core/go/common/crypto/signature" + staking "github.com/oasislabs/oasis-core/go/staking/api" +) + +func literalPublicKeyHex(h string) (k signature.PublicKey) { + if err := k.UnmarshalHex(h); err != nil { + panic(err) + } + return +} + +func TestIsTransferPermitted(t *testing.T) { + for _, tt := range []struct { + msg string + params *staking.ConsensusParameters + fromID signature.PublicKey + permitted bool + }{ + { + "no disablement", + &staking.ConsensusParameters{}, + signature.PublicKey{}, + true, + }, + { + "all disabled", + &staking.ConsensusParameters{ + DisableTransfers: true, + }, + signature.PublicKey{}, + false, + }, + { + "not whitelisted", + &staking.ConsensusParameters{ + DisableTransfers: true, + UndisableTransfersFrom: map[signature.PublicKey]bool{ + signature.PublicKey{1}: true, + }, + }, + signature.PublicKey{}, + false, + }, + { + "whitelisted", + &staking.ConsensusParameters{ + DisableTransfers: true, + UndisableTransfersFrom: map[signature.PublicKey]bool{ + signature.PublicKey{}: true, + }, + }, + signature.PublicKey{}, + true, + }, + } { + require.Equal(t, tt.permitted, isTransferPermitted(tt.params, tt.fromID), tt.msg) + } +}