From 98f0bd45e941c0607640d4a022339326c0f1fb91 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 9 Feb 2017 21:05:45 -0500 Subject: [PATCH] add tests to test_app --- .gitignore | 1 + test_app/app/contracts/token.sol | 65 +++++++++++++++++++++++++++ test_app/app/js/_vendor/async.min.js | 2 + test_app/app/js/test.js | 53 ++++++++++++++++++++++ test_app/app/test.html | 12 +++++ test_app/chains.json | 15 ------- test_app/config/contracts.json | 15 +++++++ test_app/embark.json | 5 ++- test_app/test/another_storage_spec.js | 13 +++++- test_app/test/token_spec.js | 64 ++++++++++++++++++++++++++ 10 files changed, 227 insertions(+), 18 deletions(-) create mode 100644 test_app/app/contracts/token.sol create mode 100644 test_app/app/js/_vendor/async.min.js create mode 100644 test_app/app/js/test.js create mode 100644 test_app/app/test.html delete mode 100644 test_app/chains.json create mode 100644 test_app/test/token_spec.js diff --git a/.gitignore b/.gitignore index b531da53..75be4c5f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ test_app/dist/ test_app/.embark/development/ test_app/config/production/password test_app/node_modules/ +test_app/chains.json diff --git a/test_app/app/contracts/token.sol b/test_app/app/contracts/token.sol new file mode 100644 index 00000000..9d5c34f8 --- /dev/null +++ b/test_app/app/contracts/token.sol @@ -0,0 +1,65 @@ +// https://github.com/nexusdev/erc20/blob/master/contracts/base.sol + +pragma solidity ^0.4.2; +contract Token { + + event Transfer(address indexed from, address indexed to, uint value); + event Approval( address indexed owner, address indexed spender, uint value); + + mapping( address => uint ) _balances; + mapping( address => mapping( address => uint ) ) _approvals; + uint public _supply; + function Token( uint initial_balance ) { + _balances[msg.sender] = initial_balance; + _supply = initial_balance; + } + function totalSupply() constant returns (uint supply) { + return _supply; + } + function balanceOf( address who ) constant returns (uint value) { + return _balances[who]; + } + function transfer( address to, uint value) returns (bool ok) { + if( _balances[msg.sender] < value ) { + throw; + } + if( !safeToAdd(_balances[to], value) ) { + throw; + } + _balances[msg.sender] -= value; + _balances[to] += value; + Transfer( msg.sender, to, value ); + return true; + } + function transferFrom( address from, address to, uint value) returns (bool ok) { + // if you don't have enough balance, throw + if( _balances[from] < value ) { + throw; + } + // if you don't have approval, throw + if( _approvals[from][msg.sender] < value ) { + throw; + } + if( !safeToAdd(_balances[to], value) ) { + throw; + } + // transfer and return true + _approvals[from][msg.sender] -= value; + _balances[from] -= value; + _balances[to] += value; + Transfer( from, to, value ); + return true; + } + function approve(address spender, uint value) returns (bool ok) { + // TODO: should increase instead + _approvals[msg.sender][spender] = value; + Approval( msg.sender, spender, value ); + return true; + } + function allowance(address owner, address spender) constant returns (uint _allowance) { + return _approvals[owner][spender]; + } + function safeToAdd(uint a, uint b) internal returns (bool) { + return (a + b >= a); + } +} diff --git a/test_app/app/js/_vendor/async.min.js b/test_app/app/js/_vendor/async.min.js new file mode 100644 index 00000000..f0697dea --- /dev/null +++ b/test_app/app/js/_vendor/async.min.js @@ -0,0 +1,2 @@ +!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.async=n.async||{})}(this,function(n){"use strict";function t(n,t,e){switch(e.length){case 0:return n.call(t);case 1:return n.call(t,e[0]);case 2:return n.call(t,e[0],e[1]);case 3:return n.call(t,e[0],e[1],e[2])}return n.apply(t,e)}function e(n,e,r){return e=rt(void 0===e?n.length-1:e,0),function(){for(var u=arguments,o=-1,i=rt(u.length-e,0),c=Array(i);++o-1&&n%1==0&&n<=kt}function p(n){return null!=n&&s(n.length)&&!l(n)}function h(){}function y(n){return function(){if(null!==n){var t=n;n=null,t.apply(this,arguments)}}}function v(n,t){for(var e=-1,r=Array(n);++e-1&&n%1==0&&nu?0:u+t),e=e>u?u:e,e<0&&(e+=u),u=t>e?0:e-t>>>0,t>>>=0;for(var o=Array(u);++r=r?n:K(n,t,e)}function Y(n,t){for(var e=n.length;e--&&Q(t,n[e],0)>-1;);return e}function Z(n,t){for(var e=-1,r=n.length;++e-1;);return e}function nn(n){return n.split("")}function tn(n){return We.test(n)}function en(n){return n.match(fr)||[]}function rn(n){return tn(n)?en(n):nn(n)}function un(n){return null==n?"":J(n)}function on(n,t,e){if(n=un(n),n&&(e||void 0===t))return n.replace(ar,"");if(!n||!(t=J(t)))return n;var r=rn(n),u=rn(t),o=Z(r,u),i=Y(r,u)+1;return X(r,o,i).join("")}function cn(n){return n=n.toString().replace(hr,""),n=n.match(lr)[2].replace(" ",""),n=n?n.split(sr):[],n=n.map(function(n){return on(n.replace(pr,""))})}function fn(n,t){var e={};C(n,function(n,t){function r(t,e){var r=G(u,function(n){return t[n]});r.push(e),n.apply(null,r)}var u;if(Ft(n))u=n.slice(0,-1),n=n[n.length-1],e[t]=u.concat(u.length>0?r:n);else if(1===n.length)e[t]=n;else{if(u=cn(n),0===n.length&&0===u.length)throw new Error("autoInject task functions require explicit parameters.");u.pop(),e[t]=u.concat(r)}}),Me(e,t)}function an(n){setTimeout(n,0)}function ln(n){return u(function(t,e){n(function(){t.apply(null,e)})})}function sn(){this.head=this.tail=null,this.length=0}function pn(n,t){n.length=1,n.head=n.tail=t}function hn(n,t,e){function r(n,t,e){if(null!=e&&"function"!=typeof e)throw new Error("task callback must be a function");if(f.started=!0,Ft(n)||(n=[n]),0===n.length&&f.idle())return dr(function(){f.drain()});for(var r=0,u=n.length;r=0&&c.splice(o),u.callback.apply(u,t),null!=t[0]&&f.error(t[0],u.data)}i<=f.concurrency-f.buffer&&f.unsaturated(),f.idle()&&f.drain(),f.process()})}if(null==t)t=1;else if(0===t)throw new Error("Concurrency must not be zero");var i=0,c=[],f={_tasks:new sn,concurrency:t,payload:e,saturated:h,unsaturated:h,buffer:t/4,empty:h,drain:h,error:h,started:!1,paused:!1,push:function(n,t){r(n,!1,t)},kill:function(){f.drain=h,f._tasks.empty()},unshift:function(n,t){r(n,!0,t)},process:function(){for(;!f.paused&&i3?(i=i||h,n(r,u,f,c)):(i=o,i=i||h,o=u,n(r,f,c))}}function bn(n,t){return t}function jn(n){return u(function(t,e){t.apply(null,e.concat([u(function(t,e){"object"==typeof console&&(t?console.error&&console.error(t):console[n]&&D(e,function(t){console[n](t)}))})]))})}function Sn(n,t,e){function r(t,r){return t?e(t):r?void n(o):e(null)}e=I(e||h);var o=u(function(n,u){return n?e(n):(u.push(r),void t.apply(this,u))});r(null,!0)}function kn(n,t,e){e=I(e||h);var r=u(function(u,o){return u?e(u):t.apply(this,o)?n(r):void e.apply(null,[null].concat(o))});n(r)}function wn(n,t,e){kn(n,function(){return!t.apply(this,arguments)},e)}function xn(n,t,e){function r(t){return t?e(t):void n(u)}function u(n,u){return n?e(n):u?void t(r):e(null)}e=I(e||h),n(u)}function On(n){return function(t,e,r){return n(t,r)}}function En(n,t,e){Ee(n,On(t),e)}function Ln(n,t,e,r){_(t)(n,On(e),r)}function An(n){return ut(function(t,e){var r=!0;t.push(function(){var n=arguments;r?dr(function(){e.apply(null,n)}):e.apply(null,n)}),n.apply(this,t),r=!1})}function Tn(n){return!n}function Fn(n){return function(t){return null==t?void 0:t[n]}}function In(n,t,e,r){var u=new Array(t.length);n(t,function(n,t,r){e(n,function(n,e){u[t]=!!e,r(n)})},function(n){if(n)return r(n);for(var e=[],o=0;o1&&(r=t),e(null,{value:r})}})),n.apply(this,t)})}function Wn(n,t,e,r){Bn(n,t,function(n,t){e(n,function(n,e){t(n,!e)})},r)}function Nn(n){var t;return Ft(n)?t=G(n,$n):(t={},C(n,function(n,e){t[e]=$n.call(this,n)})),t}function Qn(n){return function(){return n}}function Gn(n,t,e){function r(n,t){if("object"==typeof t)n.times=+t.times||o,n.intervalFunc="function"==typeof t.interval?t.interval:Qn(+t.interval||i),n.errorFilter=t.errorFilter;else{if("number"!=typeof t&&"string"!=typeof t)throw new Error("Invalid arguments for async.retry");n.times=+t||o}}function u(){t(function(n){n&&f++r?1:0}Le(n,function(n,e){t(n,function(t,r){return t?e(t):void e(null,{value:n,criteria:r})})},function(n,t){return n?e(n):void e(null,G(t.sort(r),Fn("value")))})}function Kn(n,t,e){function r(){c||(o.apply(null,arguments),clearTimeout(i))}function u(){var t=n.name||"anonymous",r=new Error('Callback function "'+t+'" timed out.');r.code="ETIMEDOUT",e&&(r.info=e),c=!0,o(r)}var o,i,c=!1;return ut(function(e,c){o=c,i=setTimeout(u,t),n.apply(null,e.concat(r))})}function Xn(n,t,e,r){for(var u=-1,o=Kr(Jr((t-n)/(e||1)),0),i=Array(o);o--;)i[r?o:++u]=n,n+=e;return i}function Yn(n,t,e,r){Te(Xn(0,n,1),t,e,r)}function Zn(n,t,e,r){3===arguments.length&&(r=e,e=t,t=Ft(n)?[]:{}),r=y(r||h),Ee(n,function(n,r,u){e(t,n,r,u)},function(n){r(n,t)})}function nt(n){return function(){return(n.unmemoized||n).apply(null,arguments)}}function tt(n,t,e){if(e=I(e||h),!n())return e(null);var r=u(function(u,o){return u?e(u):n()?t(r):void e.apply(null,[null].concat(o))});t(r)}function et(n,t,e){tt(function(){return!n.apply(this,arguments)},t,e)}var rt=Math.max,ut=function(n){return u(function(t){var e=t.pop();n.call(this,t,e)})},ot="object"==typeof global&&global&&global.Object===Object&&global,it="object"==typeof self&&self&&self.Object===Object&&self,ct=ot||it||Function("return this")(),ft=ct.Symbol,at=Object.prototype,lt=at.hasOwnProperty,st=at.toString,pt=ft?ft.toStringTag:void 0,ht=Object.prototype,yt=ht.toString,vt="[object Null]",dt="[object Undefined]",mt=ft?ft.toStringTag:void 0,gt="[object AsyncFunction]",bt="[object Function]",jt="[object GeneratorFunction]",St="[object Proxy]",kt=9007199254740991,wt="function"==typeof Symbol&&Symbol.iterator,xt=function(n){return wt&&n[wt]&&n[wt]()},Ot="[object Arguments]",Et=Object.prototype,Lt=Et.hasOwnProperty,At=Et.propertyIsEnumerable,Tt=m(function(){return arguments}())?m:function(n){return d(n)&&Lt.call(n,"callee")&&!At.call(n,"callee")},Ft=Array.isArray,It="object"==typeof n&&n&&!n.nodeType&&n,_t=It&&"object"==typeof module&&module&&!module.nodeType&&module,Bt=_t&&_t.exports===It,Mt=Bt?ct.Buffer:void 0,Ut=Mt?Mt.isBuffer:void 0,zt=Ut||g,Vt=9007199254740991,Pt=/^(?:0|[1-9]\d*)$/,qt="[object Arguments]",Dt="[object Array]",Rt="[object Boolean]",Ct="[object Date]",$t="[object Error]",Wt="[object Function]",Nt="[object Map]",Qt="[object Number]",Gt="[object Object]",Ht="[object RegExp]",Jt="[object Set]",Kt="[object String]",Xt="[object WeakMap]",Yt="[object ArrayBuffer]",Zt="[object DataView]",ne="[object Float32Array]",te="[object Float64Array]",ee="[object Int8Array]",re="[object Int16Array]",ue="[object Int32Array]",oe="[object Uint8Array]",ie="[object Uint8ClampedArray]",ce="[object Uint16Array]",fe="[object Uint32Array]",ae={};ae[ne]=ae[te]=ae[ee]=ae[re]=ae[ue]=ae[oe]=ae[ie]=ae[ce]=ae[fe]=!0,ae[qt]=ae[Dt]=ae[Yt]=ae[Rt]=ae[Zt]=ae[Ct]=ae[$t]=ae[Wt]=ae[Nt]=ae[Qt]=ae[Gt]=ae[Ht]=ae[Jt]=ae[Kt]=ae[Xt]=!1;var le,se="object"==typeof n&&n&&!n.nodeType&&n,pe=se&&"object"==typeof module&&module&&!module.nodeType&&module,he=pe&&pe.exports===se,ye=he&&ot.process,ve=function(){try{return ye&&ye.binding("util")}catch(n){}}(),de=ve&&ve.isTypedArray,me=de?S(de):j,ge=Object.prototype,be=ge.hasOwnProperty,je=Object.prototype,Se=x(Object.keys,Object),ke=Object.prototype,we=ke.hasOwnProperty,xe={},Oe=M(B,1/0),Ee=function(n,t,e){var r=p(n)?U:Oe;r(n,t,e)},Le=z(V),Ae=o(Le),Te=P(V),Fe=M(Te,1),Ie=o(Fe),_e=u(function(n,t){return u(function(e){return n.apply(null,t.concat(e))})}),Be=R(),Me=function(n,t,e){function r(n,t){b.push(function(){f(n,t)})}function o(){if(0===b.length&&0===d)return e(null,v);for(;b.length&&d1?o(v,r):o(r)}}function a(){for(var n,t=0;j.length;)n=j.pop(),t++,D(l(n),function(n){0===--S[n]&&j.push(n)});if(t!==p)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function l(t){var e=[];return C(n,function(n,r){Ft(n)&&Q(n,t,0)>=0&&e.push(r)}),e}"function"==typeof t&&(e=t,t=null),e=y(e||h);var s=E(n),p=s.length;if(!p)return e(null);t||(t=p);var v={},d=0,m=!1,g={},b=[],j=[],S={};C(n,function(t,e){if(!Ft(t))return r(e,[t]),void j.push(e);var u=t.slice(0,t.length-1),o=u.length;return 0===o?(r(e,t),void j.push(e)):(S[e]=o,void D(u,function(c){if(!n[c])throw new Error("async.auto task `"+e+"` has a non-existent dependency in "+u.join(", "));i(c,function(){o--,0===o&&r(e,t)})}))}),a(),o()},Ue="[object Symbol]",ze=1/0,Ve=ft?ft.prototype:void 0,Pe=Ve?Ve.toString:void 0,qe="\\ud800-\\udfff",De="\\u0300-\\u036f\\ufe20-\\ufe23",Re="\\u20d0-\\u20f0",Ce="\\ufe0e\\ufe0f",$e="\\u200d",We=RegExp("["+$e+qe+De+Re+Ce+"]"),Ne="\\ud800-\\udfff",Qe="\\u0300-\\u036f\\ufe20-\\ufe23",Ge="\\u20d0-\\u20f0",He="\\ufe0e\\ufe0f",Je="["+Ne+"]",Ke="["+Qe+Ge+"]",Xe="\\ud83c[\\udffb-\\udfff]",Ye="(?:"+Ke+"|"+Xe+")",Ze="[^"+Ne+"]",nr="(?:\\ud83c[\\udde6-\\uddff]){2}",tr="[\\ud800-\\udbff][\\udc00-\\udfff]",er="\\u200d",rr=Ye+"?",ur="["+He+"]?",or="(?:"+er+"(?:"+[Ze,nr,tr].join("|")+")"+ur+rr+")*",ir=ur+rr+or,cr="(?:"+[Ze+Ke+"?",Ke,nr,tr,Je].join("|")+")",fr=RegExp(Xe+"(?="+Xe+")|"+cr+ir,"g"),ar=/^\s+|\s+$/g,lr=/^(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,sr=/,/,pr=/(=.+)?(\s*)$/,hr=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,yr="function"==typeof setImmediate&&setImmediate,vr="object"==typeof process&&"function"==typeof process.nextTick;le=yr?setImmediate:vr?process.nextTick:an;var dr=ln(le);sn.prototype.removeLink=function(n){return n.prev?n.prev.next=n.next:this.head=n.next,n.next?n.next.prev=n.prev:this.tail=n.prev,n.prev=n.next=null,this.length-=1,n},sn.prototype.empty=sn,sn.prototype.insertAfter=function(n,t){t.prev=n,t.next=n.next,n.next?n.next.prev=t:this.tail=t,n.next=t,this.length+=1},sn.prototype.insertBefore=function(n,t){t.prev=n.prev,t.next=n,n.prev?n.prev.next=t:this.head=t,n.prev=t,this.length+=1},sn.prototype.unshift=function(n){this.head?this.insertBefore(this.head,n):pn(this,n)},sn.prototype.push=function(n){this.tail?this.insertAfter(this.tail,n):pn(this,n)},sn.prototype.shift=function(){return this.head&&this.removeLink(this.head)},sn.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)};var mr,gr=M(B,1),br=u(function(n){return u(function(t){var e=this,r=t[t.length-1];"function"==typeof r?t.pop():r=h,vn(n,t,function(n,t,r){t.apply(e,n.concat([u(function(n,t){r(n,t)})]))},function(n,t){r.apply(e,[n].concat(t))})})}),jr=u(function(n){return br.apply(null,n.reverse())}),Sr=z(dn),kr=mn(dn),wr=u(function(n){var t=[null].concat(n);return ut(function(n,e){return e.apply(this,t)})}),xr=gn(Ee,r,bn),Or=gn(B,r,bn),Er=gn(gr,r,bn),Lr=jn("dir"),Ar=M(Ln,1),Tr=gn(Ee,Tn,Tn),Fr=gn(B,Tn,Tn),Ir=M(Fr,1),_r=z(Bn),Br=P(Bn),Mr=M(Br,1),Ur=jn("log"),zr=M(Un,1/0),Vr=M(Un,1);mr=vr?process.nextTick:yr?setImmediate:an;var Pr=ln(mr),qr=function(n,t){return hn(function(t,e){n(t[0],e)},t,1)},Dr=function(n,t){var e=qr(n,t);return e.push=function(n,t,r){if(null==r&&(r=h),"function"!=typeof r)throw new Error("task callback must be a function");if(e.started=!0,Ft(n)||(n=[n]),0===n.length)return dr(function(){e.drain()});t=t||0;for(var u=e._tasks.head;u&&t>=u.priority;)u=u.next;for(var o=0,i=n.length;otest 1: " + (simpleStorageAddress === SimpleStorage.address)); + callback(); + }); + }, + function test2(callback) { + SimpleStorage.storedData().then(function(result) { + $("#tests").append("
test 2 (true first time): " + (result.toNumber() === 100)); + $("#tests").append("
test 2 (true after): " + (result.toNumber() === 150)); + callback(); + }); + }, + function test3(callback) { + SimpleStorage.set(150).then(function() { + SimpleStorage.get().then(function(result) { + $("#tests").append("
test 3: " + (result.toNumber() === 150)); + callback(); + }); + }); + }, + function test4(callback) { + $("#tests").append("
test 4: " + (Token.address === "undefined")); + $("#tests").append("
test 4: " + (MyToken.address !== undefined)); + $("#tests").append("
test 4: " + (MyToken2.address !== undefined)); + callback(); + }, + function test5(callback) { + MyToken._supply().then(function(result) { + $("#tests").append("
test 5: " + (result.toNumber() === 1000)); + callback(); + }); + }, + function test6(callback) { + MyToken2._supply().then(function(result) { + $("#tests").append("
test 6: " + (result.toNumber() === 2000)); + callback(); + }); + }, + function test7(callback) { + $("#tests").append("
test 7: " + (AlreadyDeployedToken.address === "0x123")); + callback(); + } + ], function (err, result) { + $("#tests").append("
done"); + }); + +}); + diff --git a/test_app/app/test.html b/test_app/app/test.html new file mode 100644 index 00000000..6dcd27cc --- /dev/null +++ b/test_app/app/test.html @@ -0,0 +1,12 @@ + + + Embark - TestApp + + + + + +
+ + + diff --git a/test_app/chains.json b/test_app/chains.json deleted file mode 100644 index 3f2d5c31..00000000 --- a/test_app/chains.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "0xb6cfeab83614da04c03db0fb8a6787a45d0be8d576fcc6f8f457a5a816d22ab3": { - "name": "development", - "contracts": { - "0x54e0e43bdd12bfce76988ea8f9e936bcdbfff7d5ba494a2522666c4cd57c1490": { - "address": "0x5520587bfafb95e2ef4ed26bb56571050fd3e1b2", - "name": "SimpleStorage" - }, - "0x5bfc346ae2758ec398e301cd18b5b42e31817ef2c0eba0de8d921eee73310477": { - "address": "0x042cc0d1ea786d15ad62a025c63fbd47ebdf3237", - "name": "AnotherStorage" - } - } - } -} \ No newline at end of file diff --git a/test_app/config/contracts.json b/test_app/config/contracts.json index e95affbb..dd13e8ae 100644 --- a/test_app/config/contracts.json +++ b/test_app/config/contracts.json @@ -11,6 +11,21 @@ "args": [ "$SimpleStorage" ] + }, + "Token": { + "deploy": false, + "args": [1000] + }, + "MyToken": { + "instanceOf": "Token" + }, + "MyToken2": { + "instanceOf": "Token", + "args": [2000] + }, + "AlreadyDeployedToken": { + "address": "0x123", + "instanceOf": "Token" } } } diff --git a/test_app/embark.json b/test_app/embark.json index b44c593e..731b6063 100644 --- a/test_app/embark.json +++ b/test_app/embark.json @@ -4,11 +4,12 @@ "css/app.css": ["app/css/**"], "images/": ["app/images/**"], "js/app.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/bootstrap.min.js", "app/js/**"], - "index.html": "app/index.html" + "index.html": "app/index.html", + "test.html": "app/test.html" }, "buildDir": "dist/", "config": "config/", "plugins": { - "embark-babel": {} + "embark-babel": {"files": ["**/*.js", "**/*.jsx", "!**/_vendor/*.js"]} } } diff --git a/test_app/test/another_storage_spec.js b/test_app/test/another_storage_spec.js index 10012a96..e06e11bb 100644 --- a/test_app/test/another_storage_spec.js +++ b/test_app/test/another_storage_spec.js @@ -11,12 +11,23 @@ describe("AnotherStorage", function() { }, "AnotherStorage": { args: ["$SimpleStorage"] + }, + "Token": { + deploy: false, + args: [1000] + }, + "MyToken": { + instanceOf: "Token" + }, + "MyToken2": { + instanceOf: "Token", + args: [2000] } }; EmbarkSpec.deployAll(contractsConfig, done); }); - it("should set constructor value", function(done) { + it("set SimpleStorage address", function(done) { AnotherStorage.simpleStorageAddress(function(err, result) { assert.equal(result.toString(), SimpleStorage.address); done(); diff --git a/test_app/test/token_spec.js b/test_app/test/token_spec.js new file mode 100644 index 00000000..3ed82f67 --- /dev/null +++ b/test_app/test/token_spec.js @@ -0,0 +1,64 @@ +var assert = require('assert'); +var Embark = require('embark'); +var EmbarkSpec = Embark.initTests(); +var web3 = EmbarkSpec.web3; + +describe("Token", function() { + before(function(done) { + var contractsConfig = { + "SimpleStorage": { + args: [100] + }, + "AnotherStorage": { + args: ["$SimpleStorage"] + }, + "Token": { + deploy: false, + args: [1000] + }, + "MyToken": { + instanceOf: "Token" + }, + "MyToken2": { + instanceOf: "Token", + args: [2000] + }, + "AlreadyDeployedToken": { + "address": "0x123", + instanceOf: "Token" + } + }; + EmbarkSpec.deployAll(contractsConfig, done); + }); + + it("not deploy Token", function(done) { + assert.equal(Token.address, "undefined"); + done(); + }); + + it("not deploy MyToken and MyToken2", function(done) { + assert.notEqual(MyToken.address, "undefined"); + assert.notEqual(MyToken2.address, "undefined"); + done(); + }); + + it("set MyToken Balance correctly", function(done) { + MyToken._supply(function(err, result) { + assert.equal(result.toNumber(), 1000); + done(); + }); + }); + + it("set MyToken2 Balance correctly", function(done) { + MyToken2._supply(function(err, result) { + assert.equal(result.toNumber(), 2000); + done(); + }); + }); + + it("get right address", function(done) { + assert.equal(AlreadyDeployedToken.address, "0x123"); + done(); + }); + +});