Skip to content

Commit

Permalink
separate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mebyz committed Feb 3, 2019
1 parent e83fb97 commit 8423b87
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 127 deletions.
82 changes: 51 additions & 31 deletions integrationTest.rho
Original file line number Diff line number Diff line change
@@ -1,42 +1,62 @@
/////////////////////////
// myRhobustContractTEST : test rhobustFactory102
new myRhobustContractTEST, ack, stdoutAck(`rho:io:stdoutAck`) in {
new myRhobustContractTEST, ack, stdoutAck(`rho:io:stdoutAck`),
ackJoe, resJoe,
ackIrs, resIrs,
ackBoss, resBoss,
resProc_Joe,ackProc_Joe,
resProc_Irs,ackProc_Irs,
resProc_Boss,ackProc_Boss
in {

stdoutAck!("TEST : Creating sample rhobust contract. 3 agents (employer, employee, IRS)", *ack)
| // <- concurrent (log test start)
@"rhobustFactory012"!(*myRhobustContractTEST, 3)
| // <- concurrent (run test)
// This levels of recursivity is only needed to simulate a sequential test.
// In real life, agents interact INDEPENDENTLY and sometimes CONCURRENTLY.
for(_ <- ack) {
myRhobustContractTEST!("Joe", "secretkey_employee", *ack)
| // <- concurrent (callback)
for(res <- ack) {
stdoutAck!(*res, *ack)
| // <- concurrent (callback)
for(_ <- ack) {
myRhobustContractTEST!("irs", "secretkey_irs", *ack)
| // <- concurrent (callback)
for(res <- ack) {
stdoutAck!(*res, *ack)
| // <- concurrent (callback)
for(_ <- ack) {
myRhobustContractTEST!("boss", "secretkey_employer" , *ack)
| // <- concurrent (callback)
for(res <- ack) {
stdoutAck!(*res, *ack)
| // <- concurrent (callback)
for(_ <- ack) {
myRhobustContractTEST!("Sam", "dummy_key", *ack)
| // <- concurrent (callback)
for(res <- ack) {
stdoutAck!(*res, *ack)
}
}
// TEST RhobustContracts
// The level of recursivity shown in this test is needed to simulate sequential actions of each agent
// In real life, agents interact INDEPENDENTLY and sometimes CONCURRENTLY.
// in Rholang, concurrency is handled gracefully. this is why simulating sequencial actions is harder ^^
new myRhobustContractTEST, myRhobustContract_Joe , myRhobustContract_Irs , myRhobustContract_Boss, ack,
stdout(`rho:io:stdout`), stdoutAck(`rho:io:stdoutAck`) in {
stdout!("TEST STEP 1 : Creating sample rhobust contract") |
@"RhobustFactory"!(*myRhobustContractTEST, 3, *ack) |
for(@uri2 <- ack) {
//stdout!(uri2) |

// uri2 is sent to all 3 agents.

// Agent A (Joe) stores uri2 in a safe place
// Agent B (IRS) stores uri2 in a safe place
// Agent C (boss) stores uri2 in a safe place


// Later on, agent A (Joe) logs in to sign the contract
// this results in a lookup in the tuplespace using uri
@"RhobustFactory"!(*myRhobustContract_Joe, uri2,"sign", "Joe","secretkey_employee", *ackJoe) |
for(resJoe <- ackJoe) {
stdout!(*resJoe) |



// Later on, agent B (irs) logs in to sign the contract
// this results in a lookup in the tuplespace using uri
@"RhobustFactory"!(*myRhobustContract_Irs, uri2,"sign", "irs","secretkey_irs", *ackIrs) |
for(resIrs <- ackIrs) {
stdout!(*resIrs) |



// Later on, agent C (boss) logs in to sign the contract
// this results in a lookup in the tuplespace using uri
@"RhobustFactory"!(*myRhobustContract_Boss, uri2,"sign", "boss","secretkey_employer", *ackBoss) |
for(resBoss <- ackBoss){
stdout!(*resBoss)

// identification done for boss
// + payment done (lots of thing happened)

}
}
}
}
}
}
}
110 changes: 16 additions & 94 deletions rhobustCaller.rho
Original file line number Diff line number Diff line change
@@ -1,69 +1,43 @@
// [email protected]

new
doubler,
uriChan,
contractCh,

stdout(`rho:io:stdout`),
ri(`rho:registry:insertArbitrary`),
rl(`rho:registry:lookup`),
stdoutAck(`rho:io:stdoutAck`),
RhobustContract,
Object,
super,
ackContract,
ackJoe,
resJoe,
ackIrs,
resIrs,
ackBoss,
resBoss,
ackInfo,
resInfo,
contractCh,
ackContract,
ackInfo,resInfo,
ackRegister,
resRegister,
ackRl,
resRl,
ackRl,resRl,
ack,
pay,
invoiceId,
invoiceAmount,
invoiceName,
processIncomeTax,
widthdraw,
taxPay,
pay, ackPay,
invoiceId, invoiceAmount, invoiceName,
processIncomeTax, widthdraw, taxPay,
logResolve,
uriChan,
uriChan2,
uri2,
logTransaction,resgettest,ackgettest,ct2,contractCh2,agentType,secretKey,
resProc_Joe,ackProc_Joe,
resProc_Irs,ackProc_Irs,
resProc_Boss,ackProc_Boss,
ackwithdraw,
acktaxPay,
ackprocessIncomeTax,
RhobustContractSign,ackRhobustContractSign,ackPay
uriChan, uriChan2, uri2,
logTransaction,
agentType,secretKey,
ackwithdraw,acktaxPay,ackprocessIncomeTax,
RhobustContractSign,ackRhobustContractSign
in {


contract @"rhobustFactory012"(rhobustCreation, @n, result) = {
contract @"RhobustFactory"(rhobustCreation, @n, result) = {
new
ri(`rho:registry:insertArbitrary`),
rl(`rho:registry:lookup`) in {
// store the contracts
ri!(bundle+{*RhobustContract} , *uriChan) |
// Wait for URI response
for(@uri <- uriChan) {
// lookup again using uri
rl!(uri, *contractCh) |
for( ct <- contractCh) {
ct!("new",[Nil,{"contract_id": uri, "data": true},*ackContract]) |
ct!("new",[{"contract_id": uri, "data": true},*ackContract]) |
for ( myContract <- ackContract) {
// store the instance of the contract
ri!(bundle+{*myContract} , *uriChan2) |
// Wait for URI response
for(@uri2 <- uriChan2) {
// send back the final contract instance uri
result!(uri2)
Expand All @@ -74,71 +48,19 @@ in {
}
} |

contract @"rhobustFactory012"(rhobustLookup, @uri, @action, @name, @key, resultLookup) = {
// resultLookup!(uri)
contract @"RhobustFactory"(rhobustLookup, @uri, @action, @name, @key, resultLookup) = {
rl!(uri, *contractCh) |
for( ct <- contractCh) {
//resultLookup!(uri)
//resultLookup!([ "OK", uri, action, name, key])
RhobustContractSign!(name, key, *ackRhobustContractSign) |
for(@resRhobustContractSign <- ackRhobustContractSign) {
resultLookup!(resRhobustContractSign)
}
}

} |

// TEST RhobustContracts
// This level of recursivity is only needed to simulate sequential actions of each agent
// In real life, agents interact INDEPENDENTLY and sometimes CONCURRENTLY.
new myRhobustContractTEST, myRhobustContract_Joe , myRhobustContract_Irs , myRhobustContract_Boss, ack,
stdout(`rho:io:stdout`), stdoutAck(`rho:io:stdoutAck`) in {
stdout!("TEST STEP 1 : Creating sample rhobust contract") |
@"rhobustFactory012"!(*myRhobustContractTEST, 3, *ack) |
for(@uri2 <- ack) {
//stdout!(uri2) |

// uri2 is sent to all 3 agents.

// Agent A (Joe) stores uri2 in a safe place
// Agent B (IRS) stores uri2 in a safe place
// Agent C (boss) stores uri2 in a safe place


// Later on, agent A (Joe) logs in to sign the contract
// this results in a lookup in the tuplespace using uri
@"rhobustFactory012"!(*myRhobustContract_Joe, uri2,"sign", "Joe","secretkey_employee", *ackJoe) |
for(resJoe <- ackJoe) {
stdout!(*resJoe) |



// Later on, agent B (irs) logs in to sign the contract
// this results in a lookup in the tuplespace using uri
@"rhobustFactory012"!(*myRhobustContract_Irs, uri2,"sign", "irs","secretkey_irs", *ackIrs) |
for(resIrs <- ackIrs) {
stdout!(*resIrs) |



// Later on, agent C (boss) logs in to sign the contract
// this results in a lookup in the tuplespace using uri
@"rhobustFactory012"!(*myRhobustContract_Boss, uri2,"sign", "boss","secretkey_employer", *ackBoss) |
for(resBoss <- ackBoss){
stdout!(*resBoss)

// identification done for boss
// + payment done (lots of thing happened)

}
}
}
}
} |

// class method to create a new RhobustContract
contract RhobustContract(@"new", @[
super,
contract RhobustContract(@"new", @[
propsMap,
*return]) = { // return the address (name/channel) of the new RhobustContract Object
new instance, ret in {
Expand Down
4 changes: 2 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ app.listen(uiPort, () => {
app.post('/register', (req, res) => {

let ack = Math.random().toString(36).substring(7)
let code = `@"rhobustFactory012"!("${req.body.id}", ${req.body.n}, "${ack}")`
let code = `@"RhobustFactory"!("${req.body.id}", ${req.body.n}, "${ack}")`
console.log(code)
let deployData = {term: code,
timestamp: new Date().valueOf(),
Expand Down Expand Up @@ -67,7 +67,7 @@ app.post('/call', (req, res) => {
// TODO this should be unforgeable. Can I make one from JS?
let ack = Math.random().toString(36).substring(7)
//console.log(req.body)
let code = `@"rhobustFactory012"!("${req.body.id}","${req.body.uri}","sign","${req.body.name}","${req.body.key}", "${ack}")`
let code = `@"RhobustFactory"!("${req.body.id}","${req.body.uri}","sign","${req.body.name}","${req.body.key}", "${ack}")`
console.log(code)
let deployData = {term: code,
timestamp: new Date().valueOf(),
Expand Down

0 comments on commit 8423b87

Please sign in to comment.