From b37d175e59cda8c6afd6b4b1d6b7ed921dc59279 Mon Sep 17 00:00:00 2001 From: Péter Szilágyi Date: Thu, 8 Dec 2016 14:42:31 +0200 Subject: accounts, internal, mobile: polish accounts API, extend Android tests --- mobile/android_test.go | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'mobile/android_test.go') diff --git a/mobile/android_test.go b/mobile/android_test.go index 0a3fa93ae..9e38c1986 100644 --- a/mobile/android_test.go +++ b/mobile/android_test.go @@ -14,9 +14,6 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -// Contains all the wrappers from the accounts package to support client side key -// management on mobile platforms. - package geth import ( @@ -46,14 +43,42 @@ public class AndroidTest extends InstrumentationTestCase { public AndroidTest() {} public void testAccountManagement() { - try { - AccountManager am = new AccountManager(getInstrumentation().getContext().getFilesDir() + "/keystore", Geth.LightScryptN, Geth.LightScryptP); + // Create an encrypted keystore manager with light crypto parameters. + AccountManager am = new AccountManager(getInstrumentation().getContext().getFilesDir() + "/keystore", Geth.LightScryptN, Geth.LightScryptP); + try { + // Create a new account with the specified encryption passphrase. Account newAcc = am.newAccount("Creation password"); + + // Export the newly created account with a different passphrase. The returned + // data from this method invocation is a JSON encoded, encrypted key-file. byte[] jsonAcc = am.exportKey(newAcc, "Creation password", "Export password"); - am.deleteAccount(newAcc, "Creation password"); + // Update the passphrase on the account created above inside the local keystore. + am.updateAccount(newAcc, "Creation password", "Update password"); + + // Delete the account updated above from the local keystore. + am.deleteAccount(newAcc, "Update password"); + + // Import back the account we've exported (and then deleted) above with yet + // again a fresh passphrase. Account impAcc = am.importKey(jsonAcc, "Export password", "Import password"); + + // Create a new account to sign transactions with + Account signer = am.newAccount("Signer password"); + Hash txHash = new Hash("0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"); + + // Sign a transaction with a single authorization + byte[] signature = am.signWithPassphrase(signer, "Signer password", txHash.getBytes()); + + // Sign a transaction with multiple manually cancelled authorizations + am.unlock(signer, "Signer password"); + signature = am.sign(signer.getAddress(), txHash.getBytes()); + am.lock(signer.getAddress()); + + // Sign a transaction with multiple automatically cancelled authorizations + am.timedUnlock(signer, "Signer password", 1000000000); + signature = am.sign(signer.getAddress(), txHash.getBytes()); } catch (Exception e) { fail(e.toString()); } -- cgit