github.com/braveheart12/insolar-09-08-19@v0.8.7/platformpolicy/internal/wrapper_test.go (about) 1 /* 2 * Copyright 2019 Insolar Technologies 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package internal 18 19 import ( 20 "testing" 21 22 "github.com/insolar/insolar/component" 23 "github.com/insolar/insolar/platformpolicy" 24 "github.com/insolar/insolar/platformpolicy/internal/hash" 25 "github.com/insolar/insolar/platformpolicy/internal/sign" 26 "github.com/insolar/insolar/testutils" 27 "github.com/stretchr/testify/assert" 28 ) 29 30 func TestEcdsaMarshalUnmarshal(t *testing.T) { 31 count := 10000 32 data := testutils.RandomRef() 33 34 kp := platformpolicy.NewKeyProcessor() 35 provider := sign.NewECDSAProvider() 36 37 cm := component.Manager{} 38 cm.Inject(provider, hash.NewSHA3Provider()) 39 40 for i := 0; i < count; i++ { 41 privateKey, err := kp.GeneratePrivateKey() 42 assert.NoError(t, err) 43 44 signer := provider.Sign(privateKey) 45 verifier := provider.Verify(kp.ExtractPublicKey(privateKey)) 46 47 signature, err := signer.Sign(data.Bytes()) 48 assert.NoError(t, err) 49 50 assert.True(t, verifier.Verify(*signature, data.Bytes())) 51 } 52 }