github.com/Unheilbar/quorum@v1.0.0/core/state_transition_pmh_test.go (about) 1 package core 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/ethereum/go-ethereum/common" 8 "github.com/ethereum/go-ethereum/core/state" 9 "github.com/ethereum/go-ethereum/core/types" 10 "github.com/ethereum/go-ethereum/private/engine" 11 testifyassert "github.com/stretchr/testify/assert" 12 ) 13 14 type stubPmhStateTransition struct { 15 snapshot int 16 } 17 18 func (s *stubPmhStateTransition) SetTxPrivacyMetadata(pm *types.PrivacyMetadata) { 19 } 20 21 func (s *stubPmhStateTransition) IsPrivacyEnhancementsEnabled() bool { 22 return true 23 } 24 25 func (s *stubPmhStateTransition) RevertToSnapshot(val int) { 26 s.snapshot = val 27 } 28 29 func (s *stubPmhStateTransition) GetStatePrivacyMetadata(addr common.Address) (*state.PrivacyMetadata, error) { 30 return &state.PrivacyMetadata{PrivacyFlag: engine.PrivacyFlagStateValidation, CreationTxHash: common.EncryptedPayloadHash{1}}, nil 31 } 32 33 func (s *stubPmhStateTransition) CalculateMerkleRoot() (common.Hash, error) { 34 return common.Hash{}, fmt.Errorf("Unable to calculate MerkleRoot") 35 } 36 37 func (s *stubPmhStateTransition) AffectedContracts() []common.Address { 38 return make([]common.Address, 0) 39 } 40 41 func TestPrivateMessageContextVerify_WithMerkleRootCreationError(t *testing.T) { 42 assert := testifyassert.New(t) 43 stateTransitionAPI := &stubPmhStateTransition{} 44 45 pmc := newPMH(stateTransitionAPI) 46 pmc.receivedPrivacyMetadata = &engine.ExtraMetadata{ACMerkleRoot: common.Hash{1}, PrivacyFlag: engine.PrivacyFlagStateValidation} 47 pmc.snapshot = 10 48 exitEarly, err := pmc.verify(nil) 49 50 assert.Error(err, "verify must return an error due to the MerkleRoot calculation error") 51 assert.Equal(pmc.snapshot, stateTransitionAPI.snapshot, "Revert should have been called") 52 assert.True(exitEarly, "Exit early should be true") 53 }