Updated instructions and readme, fixed error with tests

This commit is contained in:
emizzle 2018-07-18 23:36:41 +02:00
parent d2a46774ea
commit 586bf4fc49
5 changed files with 17 additions and 28 deletions

View File

@ -25,10 +25,7 @@ To follow along, please use the [instructions](./instructions).
* Integrated debugger - we are currently working on this, and the developer can always use remix as an alternative
### Known issues with this dApp
##### Issues on localhost
1. Test for tweet failing
* *Cause:* there is a known error with `ganache` that sometimes causes last test does to fail with the error `ERROR: The returned value is not a convertible string`. While we don't konw the exact cause yet, we are currently investigating this issue.
* *Solution:* not yet known
2. Create account - hangs with metamask
1. Create account - hangs with metamask
* Cause - most likely non-increasing nonce issue with metamask: https://github.com/MetaMask/metamask-extension/issues/1999)
* Solution - open issue

View File

@ -81,7 +81,7 @@ contract DTwitter {
users[usernameHash].description = description;
// add entry to our owners mapping so we can retrieve
// user by their addres
// user by their address
owners[msg.sender] = usernameHash;
}
@ -132,12 +132,6 @@ contract DTwitter {
// get the username hash of the sender's account
bytes32 usernameHash = owners[msg.sender];
// reject if that user doesn't exist
require(users[usernameHash].creationDate != 0);
// ensure the retrieved user is indeed the sender
require(users[usernameHash].owner == msg.sender);
// get our user
User storage user = users[usernameHash];

View File

@ -1,5 +1,6 @@
## Contract tests
Now that we have our contract written, we can use the code generation provided by EmbarkJS to write our contract unit test cases for TDD development.
Now that we have our contract written, we can use the code generation provided by EmbarkJS to write our contract unit test cases for TDD development. Embark will code generate a DTwitter javascript object from our contract and make it accessible in our dApp by way of the `EmbarkJS` object.
> Additionally, Embark also has an API for decentralised storage (IPFS and Swarm), and decentralised communication (Whisper), which are all configurable in config files.
###### Create account transaction should be successful
Our first test is to ensure that our `createAccount` transaction is sent successfully.
```
@ -40,7 +41,7 @@ We need to ensure that our contract events subscription works correctly when som
```
DTwitter.events.NewTweet({
filter: { _from: usernameHash },
fromBlock: 1
fromBlock: 0
})
.on('data', (event) => {
assert.equal(event.returnValues.tweet, tweetContent);

View File

@ -1,7 +1,4 @@
## Coding: dApp
Embark will code generate a DTwitter javascript object from our contract and make it accessible in our dApp by way of the `EmbarkJS` object.
> Additionally, Embark also has an API for decentralised storage (IPFS and Swarm), and decentralised communication (Whisper), which are all configurable in config files.
Lets use the `EmbarkJS` API to interact with our contact in our dApp. As we update the .js files, notice how Embark watches the files and compiles as we save.
###### `CreateUser.js`
1. We need to update the `_handleChange` function that will check if a user exists as the user types in a username.
@ -36,6 +33,16 @@ const gasEstimate = await editAccount.estimateGas({ from: web3.eth.defaultAccoun
// send the transaction with our gas estimate (plus a little bit more in case the contract) state has changed since we got our estimate
const result = await editAccount.send({ from: web3.eth.defaultAccount, gas: gasEstimate + 1000 });
```
###### `DoTweet.js`
The DoTweet components sends a tweet to the contract. We will need to update the `_handleClick` even to estimate gas and call the contract's `tweet` function.
```
// estimate gas before sending tweet transaction
const gasEstimate = await tweet.estimateGas({ from: web3.eth.defaultAccount, gas: 10000000000 });
// send the tweet transaction plus a little extra gas in case the contract state
// has changed since we've done our gas estimate
await tweet.send({ from: web3.eth.defaultAccount, gas: gasEstimate + 1000 });
```
###### `UserTweets.js`
The `UserTweets` component is used to 1.) show the the profile of the user who's tweets we'd like to view, and 2.) show the tweets of the user.
1. In `_getUserDetails`, we need to get the details of the user
@ -57,15 +64,5 @@ DTwitter.events.NewTweet({
}
})
```
###### DoTweet.js
The DoTweet components sends a tweet to the contract. We will need to update the `_handleClick` even to estimate gas and call the contract's `tweet` function.
```
// estimate gas before sending tweet transaction
const gasEstimate = await tweet.estimateGas({ from: web3.eth.defaultAccount, gas: 10000000000 });
// send the tweet transaction plus a little extra gas in case the contract state
// has changed since we've done our gas estimate
await tweet.send({ from: web3.eth.defaultAccount, gas: gasEstimate + 1000 });
```
#### Run through the site and fix any errors
Let's try out the functionality on the site and fix any errors we may have introduced.

View File

@ -84,6 +84,8 @@ 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);
await tweet(tweetContent).send();
DTwitter.events.NewTweet({
filter: { _from: usernameHash },
fromBlock: 0
@ -91,8 +93,6 @@ contract("DTwitter contract", function () {
.on('data', (event) => {
assert.equal(event.returnValues.tweet, tweetContent);
});
await tweet(tweetContent).send();
});
});