Skip to content

Commit

Permalink
Merge pull request #1064 from onflow/supun/test-crypto-algo
Browse files Browse the repository at this point in the history
Add tests for crypto algorithm conversion between cadence and fvm
  • Loading branch information
SupunS committed Aug 17, 2021
2 parents c8767e3 + 4bc217e commit eccee3b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions fvm/crypto/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/rand"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/onflow/cadence/runtime"
Expand Down Expand Up @@ -303,3 +304,31 @@ func TestValidatePublicKey(t *testing.T) {
}
})
}

func TestHashingAlgorithmConversion(t *testing.T) {
hashingAlgoMapping := map[runtime.HashAlgorithm]hash.HashingAlgorithm{
runtime.HashAlgorithmSHA2_256: hash.SHA2_256,
runtime.HashAlgorithmSHA3_256: hash.SHA3_256,
runtime.HashAlgorithmSHA2_384: hash.SHA2_384,
runtime.HashAlgorithmSHA3_384: hash.SHA3_384,
runtime.HashAlgorithmKMAC128_BLS_BLS12_381: hash.KMAC128,
}

for runtimeAlgo, cryptoAlgo := range hashingAlgoMapping {
assert.Equal(t, cryptoAlgo, crypto.RuntimeToCryptoHashingAlgorithm(runtimeAlgo))
assert.Equal(t, runtimeAlgo, crypto.CryptoToRuntimeHashingAlgorithm(cryptoAlgo))
}
}

func TestSigningAlgorithmConversion(t *testing.T) {
signingAlgoMapping := map[runtime.SignatureAlgorithm]gocrypto.SigningAlgorithm{
runtime.SignatureAlgorithmECDSA_P256: gocrypto.ECDSAP256,
runtime.SignatureAlgorithmECDSA_secp256k1: gocrypto.ECDSASecp256k1,
runtime.SignatureAlgorithmBLS_BLS12_381: gocrypto.BLSBLS12381,
}

for runtimeAlgo, cryptoAlgo := range signingAlgoMapping {
assert.Equal(t, cryptoAlgo, crypto.RuntimeToCryptoSigningAlgorithm(runtimeAlgo))
assert.Equal(t, runtimeAlgo, crypto.CryptoToRuntimeSigningAlgorithm(cryptoAlgo))
}
}

0 comments on commit eccee3b

Please sign in to comment.