From aa686b1c0f764797e4a65393718ded21881e1deb Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 14 Apr 2015 16:41:21 +0200 Subject: [PATCH 1/2] Test Case for Miner Selection features. --- mix/qml/StateDialog.qml | 17 +++++++++++++++-- mix/qml/StateListModel.qml | 4 +++- mix/test/qml/TestMain.qml | 3 +++ mix/test/qml/js/TestMiner.js | 20 ++++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 mix/test/qml/js/TestMiner.js diff --git a/mix/qml/StateDialog.qml b/mix/qml/StateDialog.qml index d609808ea..a2f9a09b7 100644 --- a/mix/qml/StateDialog.qml +++ b/mix/qml/StateDialog.qml @@ -22,6 +22,8 @@ Dialog { property alias isDefault: defaultCheckBox.checked property alias model: transactionsModel property alias transactionDialog: transactionDialog + property alias minerComboBox: comboMiner + property alias newAccAction: newAccountAction property int stateIndex property var stateTransactions: [] property var stateAccounts: [] @@ -46,12 +48,11 @@ Dialog { accountsModel.clear(); stateAccounts = []; var miner = 0; - for (var k = 0; k < item.accounts.length; k++) { accountsModel.append(item.accounts[k]); stateAccounts.push(item.accounts[k]); - if (item.accounts[k].name === item.miner.name) + if (item.miner && item.accounts[k].name === item.miner.name) miner = k; } @@ -91,6 +92,7 @@ Dialog { } return item; } + contentItem: Rectangle { color: stateDialogStyle.generic.backgroundColor Rectangle { @@ -138,6 +140,7 @@ Dialog { Button { + id: newAccountButton anchors.top: accountsLabel.bottom anchors.topMargin: 10 iconSource: "qrc:/qml/img/plus.png" @@ -148,10 +151,16 @@ Dialog { id: newAccountAction tooltip: qsTr("Add new Account") onTriggered: + { + add(); + } + + function add() { var account = stateListModel.newAccount("1000000", QEther.Ether); stateAccounts.push(account); accountsModel.append(account); + return account; } } } @@ -194,8 +203,12 @@ Dialog { alertAlreadyUsed.open(); else { + if (stateAccounts[styleData.row].name === comboMiner.currentText) + comboMiner.currentIndex = 0; stateAccounts.splice(styleData.row, 1); accountsModel.remove(styleData.row); + comboMiner.model = stateAccounts; + comboMiner.update(); } } } diff --git a/mix/qml/StateListModel.qml b/mix/qml/StateListModel.qml index fbb384caf..35d106b5f 100644 --- a/mix/qml/StateListModel.qml +++ b/mix/qml/StateListModel.qml @@ -193,7 +193,9 @@ Item { accounts: [] }; - item.accounts.push(newAccount("1000000", QEther.Ether, defaultAccount)); + var account = newAccount("1000000", QEther.Ether, defaultAccount) + item.accounts.push(account); + item.miner = account; //add all stdc contracts for (var i = 0; i < contractLibrary.model.count; i++) { diff --git a/mix/test/qml/TestMain.qml b/mix/test/qml/TestMain.qml index bf449d2dd..69f37f5a4 100644 --- a/mix/test/qml/TestMain.qml +++ b/mix/test/qml/TestMain.qml @@ -4,6 +4,7 @@ import org.ethereum.qml.TestService 1.0 import "../../qml" import "js/TestDebugger.js" as TestDebugger import "js/TestTutorial.js" as TestTutorial +import "js/TestMiner.js" as TestMiner TestCase { @@ -74,5 +75,7 @@ TestCase function test_dbg_transactionWithParameter() { TestDebugger.test_transactionWithParameter(); } function test_dbg_constructorParameters() { TestDebugger.test_constructorParameters(); } function test_dbg_arrayParametersAndStorage() { TestDebugger.test_arrayParametersAndStorage(); } + function test_miner_getDefaultiner() { TestMiner.test_getDefaultMiner(); } + function test_miner_selectMiner() { TestMiner.test_selectMiner(); } } diff --git a/mix/test/qml/js/TestMiner.js b/mix/test/qml/js/TestMiner.js new file mode 100644 index 000000000..a24b0ce19 --- /dev/null +++ b/mix/test/qml/js/TestMiner.js @@ -0,0 +1,20 @@ +function test_getDefaultMiner() +{ + newProject(); + var state = mainApplication.projectModel.stateListModel.get(0); + compare(state.miner.secret, "cb73d9408c4720e230387d956eb0f829d8a4dd2c1055f96257167e14e7169074"); +} + +function test_selectMiner() +{ + newProject(); + mainApplication.projectModel.stateListModel.editState(0); + var account = mainApplication.projectModel.stateDialog.newAccAction.add(); + account = mainApplication.projectModel.stateDialog.newAccAction.add(); + mainApplication.projectModel.stateDialog.minerComboBox.currentIndex = 2; + ts.waitForRendering(mainApplication.projectModel.stateDialog.minerComboBox, 3000); + mainApplication.projectModel.stateDialog.acceptAndClose(); + var state = mainApplication.projectModel.stateListModel.get(0); + compare(state.miner.secret, account.secret); +} + From 8d2141fdf8b985f24612ba13f6dfcfd242fa206a Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 14 Apr 2015 16:52:23 +0200 Subject: [PATCH 2/2] fixed bad commit --- mix/test/qml/TestMain.qml | 3 --- 1 file changed, 3 deletions(-) diff --git a/mix/test/qml/TestMain.qml b/mix/test/qml/TestMain.qml index fb0c01adf..d1d962900 100644 --- a/mix/test/qml/TestMain.qml +++ b/mix/test/qml/TestMain.qml @@ -76,11 +76,8 @@ TestCase function test_dbg_transactionWithParameter() { TestDebugger.test_transactionWithParameter(); } function test_dbg_constructorParameters() { TestDebugger.test_constructorParameters(); } function test_dbg_arrayParametersAndStorage() { TestDebugger.test_arrayParametersAndStorage(); } -<<<<<<< HEAD function test_miner_getDefaultiner() { TestMiner.test_getDefaultMiner(); } function test_miner_selectMiner() { TestMiner.test_selectMiner(); } -======= function test_project_contractRename() { TestProject.test_contractRename(); } ->>>>>>> up/develop }