Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* createConfig deprecated * added CreateConfig with new identity * added test for create config * formatting * added tests for create config * formatting * moved create identity and add keys to did package
- Loading branch information
Showing
13 changed files
with
314 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// +build integration | ||
|
||
package cmd | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
"os" | ||
"os/exec" | ||
"path" | ||
"testing" | ||
|
||
"github.com/centrifuge/go-centrifuge/crypto/ed25519" | ||
"github.com/centrifuge/go-centrifuge/crypto/secp256k1" | ||
"github.com/centrifuge/go-centrifuge/identity" | ||
"github.com/centrifuge/go-centrifuge/testingutils" | ||
"github.com/centrifuge/go-centrifuge/testingutils/config" | ||
"github.com/centrifuge/go-centrifuge/utils" | ||
"github.com/ethereum/go-ethereum/common" | ||
|
||
"github.com/centrifuge/go-centrifuge/bootstrap" | ||
"github.com/centrifuge/go-centrifuge/bootstrap/bootstrappers/testlogging" | ||
"github.com/centrifuge/go-centrifuge/config" | ||
"github.com/centrifuge/go-centrifuge/config/configstore" | ||
"github.com/centrifuge/go-centrifuge/ethereum" | ||
"github.com/centrifuge/go-centrifuge/identity/did" | ||
"github.com/centrifuge/go-centrifuge/identity/ethid" | ||
"github.com/centrifuge/go-centrifuge/queue" | ||
"github.com/centrifuge/go-centrifuge/storage/leveldb" | ||
"github.com/centrifuge/go-centrifuge/transactions" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var cfg config.Configuration | ||
var ctx = map[string]interface{}{} | ||
|
||
func TestMain(m *testing.M) { | ||
var bootstappers = []bootstrap.TestBootstrapper{ | ||
&testlogging.TestLoggingBootstrapper{}, | ||
&config.Bootstrapper{}, | ||
&leveldb.Bootstrapper{}, | ||
transactions.Bootstrapper{}, | ||
&queue.Bootstrapper{}, | ||
ethereum.Bootstrapper{}, | ||
ðid.Bootstrapper{}, | ||
&configstore.Bootstrapper{}, | ||
&did.Bootstrapper{}, | ||
&queue.Starter{}, | ||
} | ||
|
||
bootstrap.RunTestBootstrappers(bootstappers, ctx) | ||
cfg = ctx[bootstrap.BootstrappedConfig].(config.Configuration) | ||
result := m.Run() | ||
bootstrap.RunTestTeardown(bootstappers) | ||
os.Exit(result) | ||
} | ||
|
||
func TestCreateConfig(t *testing.T) { | ||
// create config | ||
dataDir := "testconfig" | ||
keyPath := path.Join(testingutils.GetProjectDir(), "build/scripts/test-dependencies/test-ethereum/migrateAccount.json") | ||
scAddrs := did.GetSmartContractAddresses() | ||
err := CreateConfig(dataDir, "http://127.0.0.1:9545", keyPath, "", "russianhill", 8028, 38202, nil, true, "", scAddrs) | ||
assert.Nil(t, err, "Create Config should be successful") | ||
|
||
// config exists | ||
cfg := config.LoadConfiguration(path.Join(dataDir, "config.yaml")) | ||
client := ctx[ethereum.BootstrappedEthereumClient].(ethereum.Client) | ||
|
||
// contract exists | ||
id, err := cfg.GetIdentityID() | ||
assert.Nil(t, err, "did should exists") | ||
contractCode, err := client.GetEthClient().CodeAt(context.Background(), common.BytesToAddress(id), nil) | ||
assert.Nil(t, err, "should be successful to get the contract code") | ||
assert.Equal(t, true, len(contractCode) > 3000, "current contract code should be arround 3378 bytes") | ||
|
||
// Keys exists | ||
// type KeyPurposeEthMsgAuth | ||
tctx := testingconfig.CreateAccountContext(t, cfg) | ||
idSrv := ctx[did.BootstrappedDIDService].(did.Service) | ||
pk, _, err := secp256k1.GetEthAuthKey(cfg.GetEthAuthKeyPair()) | ||
assert.Nil(t, err) | ||
address32Bytes := utils.AddressTo32Bytes(common.HexToAddress(secp256k1.GetAddress(pk))) | ||
assert.Nil(t, err) | ||
response, err := idSrv.GetKey(tctx, address32Bytes) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, response) | ||
assert.Equal(t, big.NewInt(identity.KeyPurposeEthMsgAuth), response.Purposes[0], "purpose should be ETHMsgAuth") | ||
|
||
// type KeyPurposeP2P | ||
pk, _, err = ed25519.GetSigningKeyPair(cfg.GetP2PKeyPair()) | ||
assert.Nil(t, err) | ||
pk32, err := utils.SliceToByte32(pk) | ||
assert.Nil(t, err) | ||
response, _ = idSrv.GetKey(tctx, pk32) | ||
assert.NotNil(t, response) | ||
assert.Equal(t, big.NewInt(identity.KeyPurposeP2P), response.Purposes[0], "purpose should be P2P") | ||
|
||
// type KeyPurposeSigning | ||
pk, _, err = ed25519.GetSigningKeyPair(cfg.GetSigningKeyPair()) | ||
assert.Nil(t, err) | ||
pk32, err = utils.SliceToByte32(pk) | ||
assert.Nil(t, err) | ||
response, _ = idSrv.GetKey(tctx, pk32) | ||
assert.NotNil(t, response) | ||
assert.Equal(t, big.NewInt(identity.KeyPurposeSigning), response.Purposes[0], "purpose should be Signing") | ||
|
||
err = exec.Command("rm", "-rf", dataDir).Run() | ||
assert.Nil(t, err, "removing testconfig folder should be successful") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.