Guest User

Untitled

a guest
Jan 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. struct Post {
  2. uint256 amt;
  3. bool isActive;
  4. address owner;
  5. }
  6.  
  7. Post[] public posts;
  8.  
  9. function createP(uint256 amt) public payable returns(uint a) {
  10. posts.push(Post({
  11. amt: amt,
  12. isActive: false,
  13. owner: msg.sender
  14. }));
  15. return (posts.length);
  16. }
  17. function getPostLength() returns(uint a){
  18. return (posts.length);
  19. }
  20.  
  21. MyContract.deployed()
  22. .then(async instance => {
  23. const weiSpend = web3.toWei(2, "ether");
  24. var id = await instance.createP.call(10,{
  25. from: accounts[0],
  26. value: weiSpend
  27. });
  28. var id2 = await instance.createP.call(50,{
  29. from: accounts[1],
  30. value: weiSpend
  31. });
  32. var id3 = await instance.createP.call(100,{
  33. from: accounts[2],
  34. value: weiSpend
  35. });
  36. var last = await instance.getPostLength.call();
  37. console.log(id3.toString()); // returns 1 instead of 3
  38. console.log(last.toString()); // returns 0 instead of 3
  39. });
Add Comment
Please, Sign In to add comment