diff --git a/app/js/components/App.js b/app/js/components/App.js index 87a177f..480dcbe 100644 --- a/app/js/components/App.js +++ b/app/js/components/App.js @@ -42,19 +42,25 @@ class App extends Component { * @returns {null} */ _loadCurrentUser = async () => { - const accounts = await web3.eth.getAccounts(); + const accounts =  ["0xEFdE4e6C936c92816B381718AfA75F0414abfb33", "0xB767CB0BCB49c96BaCf11f9adbd55388faA0bE6b", "0x813036e8b5B2D12872135Bbd7C67B29399F346C7"]; try { // get the owner associated with the current defaultAccount - const usernameHash = await DTwitter.methods.owners(web3.eth.defaultAccount).call(); + const usernameHash = "0xc1671a7151e1edce1c1199a5d6db723cf1b0815d5f42c3e782581dde347530d6"; // get user details from contract - const user = await DTwitter.methods.users(usernameHash).call(); + const user = { + creationDate:"1531858631", + description:"this is me", + owner:"0xB767CB0BCB49c96BaCf11f9adbd55388faA0bE6b", + picture:"", + username:"emizzle" + }; // update user picture with ipfs url user.picture = user.picture.length > 0 ? EmbarkJS.Storage.getUrl(user.picture) : imgAvatar; - // get current user balance - const balance = await web3.eth.getBalance(web3.eth.defaultAccount); + // get current user (default account) balance + const balance = "5000000000000000000"; // update state with user details return this.setState({ user: user, account: web3.eth.defaultAccount, accounts: accounts, balance: web3.utils.fromWei(balance, 'ether') }); diff --git a/app/js/components/CreateUser.js b/app/js/components/CreateUser.js index b413749..6a2c1dc 100644 --- a/app/js/components/CreateUser.js +++ b/app/js/components/CreateUser.js @@ -41,14 +41,14 @@ class CreateUser extends Component { try { // set up our contract method with the input values from the form - const createAccount = DTwitter.methods.createAccount(username, description); + //const createAccount = DTwitter.methods.createAccount(username, description); // get a gas estimate before sending the transaction - const gasEstimate = await createAccount.estimateGas({ from: web3.eth.defaultAccount, gas: 10000000000 }); + //const gasEstimate = await createAccount.estimateGas({ from: web3.eth.defaultAccount, gas: 10000000000 }); // send the transaction to create an account with our gas estimate // (plus a little bit more in case the contract state has changed). - const result = await createAccount.send({ from: web3.eth.defaultAccount, gas: gasEstimate + 1000 }); + //const result = await createAccount.send({ from: web3.eth.defaultAccount, gas: gasEstimate + 1000 }); // check result status. if status is false or '0x0', show user the tx details to debug error if (result.status && !Boolean(result.status.toString().replace('0x', ''))) { // possible result values: '0x0', '0x1', or false, true diff --git a/test/dtwitter_spec.js b/test/dtwitter_spec.js index 03f6d1b..9e2621e 100644 --- a/test/dtwitter_spec.js +++ b/test/dtwitter_spec.js @@ -29,8 +29,6 @@ const tweetContent = 'test tweet'; contract("DTwitter contract", function () { this.timeout(0); - - // it(`should create a dtwitter user '${username}' with description '${description}'`, async function () { it("transaction to create a dtwitter user 'testhandle' with description 'test description' should be successful", async function () { // do the create account @@ -43,9 +41,9 @@ contract("DTwitter contract", function () { it("should have created a user 'testhandle'", async function () { - // get user details from contract - const user = await users(web3.utils.keccak256(username)).call(); + // TODO: get user details from contract + // check the values returned from the contract are correct assert.equal(user.username, username); assert.equal(user.description, description); @@ -53,8 +51,7 @@ contract("DTwitter contract", function () { it("should have created an owner for our defaultAccount", async function () { - // read from the owners mapping - const usernameHash = await owners(web3.eth.defaultAccount).call(); + // TODO: read from the owners mapping using web3.eth.defaultAccount // check the return value from owners mapping matches assert.equal(usernameHash, web3.utils.keccak256(username)); @@ -62,8 +59,11 @@ contract("DTwitter contract", function () { it("should know 'testhandle' exists", async function () { const usernameHash = web3.utils.keccak256(username); - const exists = await userExists(usernameHash).call(); + // TODO: call the contract method 'userExists' with the username + // hash to see if that username hash exists in the users mapping + + // check that the contract agrees the user exists assert.equal(exists, true); }); @@ -73,10 +73,12 @@ contract("DTwitter contract", function () { const updatedDescription = description + ' edited'; const updatedImageHash = 'QmWvPtv2xVGgdV12cezG7iCQ4hQ52e4ptmFFnBK3gTjnec'; - await editAccount(usernameHash, updatedDescription, updatedImageHash).send(); - - const updatedUserDetails = await users(usernameHash).call(); + // TODO: update the account details in our contract using the editAccount + // function in the contract + + // TODO: retrieve the updated user details from the user mapping in the contract + // check our updated values match the input assert.equal(updatedUserDetails.description, updatedDescription); assert.equal(updatedUserDetails.picture, updatedImageHash); }); @@ -84,15 +86,13 @@ contract("DTwitter contract", function () { it("should be able to add a tweet as 'testhandle' and receive it via contract event", async function () { const usernameHash = web3.utils.keccak256(username); - DTwitter.events.NewTweet({ - filter: { _from: usernameHash }, - fromBlock: 0 - }) - .on('data', (event) => { - assert.equal(event.returnValues.tweet, tweetContent); - }); + // TODO: Subscribe to the NewTweet contract event using the + // usernameHash as the _from filter. When data is received + // from the subscription, check that the tweet value from the + // contract is the same as the tweeted content. - await tweet(tweetContent).send(); + // TODO: send the tweet to the contract which should trigger + // the NewTweet event subscription above }); });