From ce43f167f036561ceb0708f36f32150f32b4dde6 Mon Sep 17 00:00:00 2001 From: Warren He Date: Mon, 23 Dec 2019 11:41:15 -0800 Subject: [PATCH 1/2] go staking: add isTransferPermitted tests --- .../apps/staking/transactions_test.go | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 go/consensus/tendermint/apps/staking/transactions_test.go 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..e1f75f5f64b --- /dev/null +++ b/go/consensus/tendermint/apps/staking/transactions_test.go @@ -0,0 +1,58 @@ +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 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) + } +} From 04b49c6c2954e3dbed44357fab24344571647e92 Mon Sep 17 00:00:00 2001 From: Warren He Date: Mon, 23 Dec 2019 11:44:46 -0800 Subject: [PATCH 2/2] add changelog --- .changelog/2503.trivial.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2503.trivial.md diff --git a/.changelog/2503.trivial.md b/.changelog/2503.trivial.md new file mode 100644 index 00000000000..c8a56eef53a --- /dev/null +++ b/.changelog/2503.trivial.md @@ -0,0 +1,3 @@ +go staking: add isTransferPermitted tests + +it was desired that we have tests for this transfer permissions engine