2019-10-29 15:50:32 +00:00
/*global contract, config, it, assert, web3*/
2020-01-24 11:04:42 +00:00
const SimpleStorage = artifacts . require ( 'SimpleStorage' ) ;
2018-06-06 17:54:20 +00:00
let accounts ;
2020-01-24 11:04:42 +00:00
const { Utils } = artifacts . require ( 'EmbarkJS' ) ;
2018-01-15 14:51:45 +00:00
2018-06-01 14:48:29 +00:00
config ( {
contracts : {
2019-08-30 20:50:20 +00:00
deploy : {
"SimpleStorage" : {
args : [ 100 ] ,
2019-10-23 18:58:40 +00:00
onDeploy : ( dependencies ) => {
return dependencies . contracts . SimpleStorage . methods . setRegistar ( dependencies . contracts . SimpleStorage . options . address ) . send ( ) ;
}
2019-08-30 20:50:20 +00:00
}
2018-06-01 14:48:29 +00:00
}
}
2018-06-06 17:54:20 +00:00
} , ( err , theAccounts ) => {
accounts = theAccounts ;
2018-06-01 14:48:29 +00:00
} ) ;
2018-01-15 14:51:45 +00:00
2018-10-25 23:11:49 +00:00
contract ( "SimpleStorage" , function ( ) {
2018-01-05 20:10:47 +00:00
this . timeout ( 0 ) ;
2018-01-15 14:51:45 +00:00
2018-10-25 23:11:49 +00:00
it ( "should set constructor value" , async function ( ) {
2018-04-17 18:48:31 +00:00
let result = await SimpleStorage . methods . storedData ( ) . call ( ) ;
2018-06-01 14:48:29 +00:00
assert . strictEqual ( parseInt ( result , 10 ) , 100 ) ;
2017-02-10 00:38:02 +00:00
} ) ;
2018-10-25 23:11:49 +00:00
it ( "set storage value" , function ( done ) {
2018-08-24 17:11:06 +00:00
Utils . secureSend ( web3 , SimpleStorage . methods . set ( 150 ) , { } , false , async function ( err ) {
if ( err ) {
return done ( err ) ;
}
let result = await SimpleStorage . methods . get ( ) . call ( ) ;
assert . strictEqual ( parseInt ( result , 10 ) , 150 ) ;
done ( ) ;
} ) ;
2017-02-10 00:38:02 +00:00
} ) ;
2018-06-06 14:39:02 +00:00
2019-10-29 15:50:32 +00:00
it ( "should set to self address" , async function ( ) {
2018-06-06 14:39:02 +00:00
let result = await SimpleStorage . methods . registar ( ) . call ( ) ;
2018-10-25 23:11:49 +00:00
assert . strictEqual ( result , SimpleStorage . options . address ) ;
} ) ;
it ( 'should have the right defaultAccount' , function ( ) {
2018-06-06 17:54:20 +00:00
assert . strictEqual ( accounts [ 0 ] , web3 . eth . defaultAccount ) ;
2018-06-06 14:39:02 +00:00
} ) ;
2018-10-25 23:11:49 +00:00
it ( "should alias contract address" , function ( ) {
2018-06-06 16:47:16 +00:00
assert . strictEqual ( SimpleStorage . options . address , SimpleStorage . address ) ;
} ) ;
2020-01-07 04:19:54 +00:00
it ( 'listens to events' , async function ( ) {
const promise = new Promise ( ( resolve ) => {
SimpleStorage . once ( "EventOnSet2" , ( error , result ) => {
assert . strictEqual ( error , null ) ;
assert . strictEqual ( parseInt ( result . returnValues . setValue , 10 ) , 150 ) ;
resolve ( ) ;
} ) ;
2018-06-12 15:38:25 +00:00
} ) ;
2020-01-07 04:19:54 +00:00
await SimpleStorage . methods . set2 ( 150 ) . send ( ) ;
// execute the same method/value twice as a workaround for getting this test
// to pass with --node=embark. The cause of the issue and how the workaround
// works is still unknown.
await SimpleStorage . methods . set2 ( 150 ) . send ( ) ;
return promise ;
2018-06-12 15:38:25 +00:00
} ) ;
2019-10-17 18:39:25 +00:00
it ( 'asserts event triggered' , async function ( ) {
const tx = await SimpleStorage . methods . set2 ( 160 ) . send ( ) ;
2019-11-11 05:40:36 +00:00
assert . eventEmitted ( tx , 'EventOnSet2' , { passed : true , message : "hi" , setValue : "160" } ) ;
2019-10-17 18:39:25 +00:00
} ) ;
it ( "should revert with a value lower than 5" , async function ( ) {
await assert . reverts ( SimpleStorage . methods . set3 ( 2 ) , { from : web3 . eth . defaultAccount } , 'Returned error: VM Exception while processing transaction: revert Value needs to be higher than 5' ) ;
} ) ;
2017-02-10 00:38:02 +00:00
} ) ;