-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from getsafle/tests
Tests
- Loading branch information
Showing
4 changed files
with
133 additions
and
1 deletion.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,42 @@ | ||
module.exports = { | ||
HD_WALLET_12_MNEMONIC_TEST_OTHER: | ||
"orange lecture tiger surround narrow much novel arrange sample balance weapon bacon", | ||
HD_WALLET_12_MNEMONIC: | ||
"affair entry detect broom axis crawl found valve bamboo taste broken hundred", | ||
HD_WALLET_24_MNEMONIC: | ||
"begin pyramid grit rigid mountain stamp legal item result peace wealth supply satoshi elegant roof identify furnace march west chicken pen gorilla spot excuse", | ||
|
||
TESTING_MESSAGE_1: "ThisMessageOneIsForTesting", | ||
TESTING_MESSAGE_2: "This_message_two_is_for_testing", | ||
TESTING_MESSAGE_3: "This message three is for testing", | ||
|
||
EXTERNAL_ACCOUNT_PRIVATE_KEY: | ||
"0xbcb7a8680126610ca94440b020280f9ef82194a4dc2760653073b5f5b150c9c3", | ||
EXTERNAL_ACCOUNT_ADDRESS: "0x9E1447ea3F6abA7a5D344B360B95Fd9BAE049448", | ||
EXTERNAL_ACCOUNT_WRONG_PRIVATE_KEY_1: "random_private_key", | ||
EXTERNAL_ACCOUNT_WRONG_PRIVATE_KEY_2: | ||
"0xbcb7a8680126610ca94440b020280f9ef829ad26637bfb5cc", | ||
EXTERNAL_ACCOUNT_WRONG_PRIVATE_KEY_3: | ||
"QUWL7cmUp9Cj9DF3gLFqqSipopXyzuF4QXmDNV3ZTZ28GB6Ug98Z", | ||
|
||
TRANSACTION_TYPE: { | ||
NATIVE_TRANSFER: "NATIVE_TRANSFER", | ||
CONTRACT_TRANSACTION: "CONTRACT_TRANSACTION", | ||
}, | ||
TRANSFER_BTC: { | ||
BTC_RECEIVER: "0xd27189917dd3E4B0e9eB731eCEe358254520FA01", // generated from HD_WALLET_12_MNEMONIC_TEST_OTHER | ||
BTC_AMOUNT: 13, | ||
}, | ||
NETWORK: { | ||
MAINNET: { | ||
NETWORK: "MAINNET", | ||
CHAIN_ID: 30, | ||
URL: "https://rpc.mainnet.rootstock.io/Ufjv34jGv6FZXRv0IsbpNjoIygQ0X4-T", | ||
}, | ||
TESTNET: { | ||
NETWORK: "TESTNET", | ||
CHAIN_ID: 31, | ||
URL: "https://rpc.testnet.rootstock.io/Ufjv34jGv6FZXRv0IsbpNjoIygQ0X4-T", | ||
}, | ||
}, | ||
}; |
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,89 @@ | ||
var assert = require("assert"); | ||
const Web3 = require("web3"); | ||
const CryptoJS = require("crypto-js"); | ||
const { | ||
KeyringController: RootStockKeyring, | ||
getBalance, | ||
} = require("../src/index"); | ||
const { | ||
HD_WALLET_12_MNEMONIC, | ||
EXTERNAL_ACCOUNT_PRIVATE_KEY, | ||
EXTERNAL_ACCOUNT_ADDRESS, | ||
NETWORK: { TESTNET, MAINNET }, | ||
} = require("./constants"); | ||
|
||
const opts = { | ||
encryptor: { | ||
encrypt(pass, object) { | ||
const ciphertext = CryptoJS.AES.encrypt( | ||
JSON.stringify(object), | ||
pass | ||
).toString(); | ||
|
||
return ciphertext; | ||
}, | ||
decrypt(pass, encryptedString) { | ||
const bytes = CryptoJS.AES.decrypt(encryptedString, pass); | ||
const decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8)); | ||
|
||
return decryptedData; | ||
}, | ||
}, | ||
}; | ||
|
||
const opts_empty = {}; | ||
|
||
const PASSWORD = "random_password"; | ||
|
||
describe("Initialize wallet ", () => { | ||
const rootstockKeyring = new RootStockKeyring(opts); | ||
|
||
it("Create new vault and keychain", async () => { | ||
const res = await rootstockKeyring.createNewVaultAndKeychain(PASSWORD); | ||
console.log("res ", res); | ||
}); | ||
|
||
it("Create new vault and restore", async () => { | ||
const res = await rootstockKeyring.createNewVaultAndRestore( | ||
PASSWORD, | ||
HD_WALLET_12_MNEMONIC | ||
); | ||
assert( | ||
rootstockKeyring.keyrings[0].mnemonic === HD_WALLET_12_MNEMONIC, | ||
"Wrong mnemonic" | ||
); | ||
}); | ||
|
||
it("Export account (privateKey)", async () => { | ||
const res = await rootstockKeyring.getAccounts(); | ||
let account = res[0]; | ||
const accRes = await rootstockKeyring.exportAccount(account); | ||
console.log("accRes ", accRes, Buffer.from(accRes, "hex")); | ||
}); | ||
|
||
it("Get accounts", async () => { | ||
const acc = await rootstockKeyring.getAccounts(); | ||
console.log("acc ", acc); | ||
}); | ||
|
||
it("Should import correct account ", async () => { | ||
const address = await rootstockKeyring.importWallet( | ||
EXTERNAL_ACCOUNT_PRIVATE_KEY | ||
); | ||
assert( | ||
address.toLowerCase() === EXTERNAL_ACCOUNT_ADDRESS.toLowerCase(), | ||
"Wrong address" | ||
); | ||
assert( | ||
rootstockKeyring.importedWallets.length === 1, | ||
"Should have 1 imported wallet" | ||
); | ||
}); | ||
|
||
it("Get address balance", async () => { | ||
const accounts = await rootstockKeyring.getAccounts(); | ||
const web3 = new Web3(TESTNET.URL); | ||
const balance = await getBalance(accounts[0], web3); | ||
console.log(" get balance ", balance, accounts); | ||
}); | ||
}); |