2019-10-29 11:50:32 -04:00
/*global contract, config, it, assert, web3*/
2020-01-24 12:04:42 +01:00
const SimpleStorage = artifacts . require ( 'SimpleStorage' ) ;
2018-06-06 13:54:20 -04:00
let accounts ;
2020-01-24 12:04:42 +01:00
const { Utils } = artifacts . require ( 'EmbarkJS' ) ;
2018-01-15 09:51:45 -05:00
2018-06-01 10:48:29 -04:00
config ( {
contracts : {
2019-08-30 15:50:20 -05:00
deploy : {
"SimpleStorage" : {
args : [ 100 ] ,
2019-10-23 14:58:40 -04:00
onDeploy : ( dependencies ) => {
return dependencies . contracts . SimpleStorage . methods . setRegistar ( dependencies . contracts . SimpleStorage . options . address ) . send ( ) ;
}
2019-08-30 15:50:20 -05:00
}
2018-06-01 10:48:29 -04:00
}
}
2018-06-06 13:54:20 -04:00
} , ( err , theAccounts ) => {
accounts = theAccounts ;
2018-06-01 10:48:29 -04:00
} ) ;
2018-01-15 09:51:45 -05:00
2018-10-25 19:11:49 -04:00
contract ( "SimpleStorage" , function ( ) {
2018-01-05 15:10:47 -05:00
this . timeout ( 0 ) ;
2018-01-15 09:51:45 -05:00
2018-10-25 19:11:49 -04:00
it ( "should set constructor value" , async function ( ) {
2018-04-17 14:48:31 -04:00
let result = await SimpleStorage . methods . storedData ( ) . call ( ) ;
2018-06-01 10:48:29 -04:00
assert . strictEqual ( parseInt ( result , 10 ) , 100 ) ;
2017-02-09 19:38:02 -05:00
} ) ;
2018-10-25 19:11:49 -04:00
it ( "set storage value" , function ( done ) {
2018-08-24 13:11:06 -04: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-09 19:38:02 -05:00
} ) ;
2018-06-06 10:39:02 -04:00
2019-10-29 11:50:32 -04:00
it ( "should set to self address" , async function ( ) {
2018-06-06 10:39:02 -04:00
let result = await SimpleStorage . methods . registar ( ) . call ( ) ;
2018-10-25 19:11:49 -04:00
assert . strictEqual ( result , SimpleStorage . options . address ) ;
} ) ;
it ( 'should have the right defaultAccount' , function ( ) {
2018-06-06 13:54:20 -04:00
assert . strictEqual ( accounts [ 0 ] , web3 . eth . defaultAccount ) ;
2018-06-06 10:39:02 -04:00
} ) ;
2018-10-25 19:11:49 -04:00
it ( "should alias contract address" , function ( ) {
2018-06-06 12:47:16 -04:00
assert . strictEqual ( SimpleStorage . options . address , SimpleStorage . address ) ;
} ) ;
2020-01-07 15:19:54 +11: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 11:38:25 -04:00
} ) ;
2020-01-07 15:19:54 +11: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 11:38:25 -04:00
} ) ;
2019-10-17 14:39:25 -04:00
it ( 'asserts event triggered' , async function ( ) {
const tx = await SimpleStorage . methods . set2 ( 160 ) . send ( ) ;
2019-11-11 16:40:36 +11:00
assert . eventEmitted ( tx , 'EventOnSet2' , { passed : true , message : "hi" , setValue : "160" } ) ;
2019-10-17 14:39:25 -04: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-09 19:38:02 -05:00
} ) ;