-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from aionnetwork/avm-support-update
Avm support update
- Loading branch information
Showing
61 changed files
with
14,551 additions
and
10,389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ dist/ | |
lerna-debug.log | ||
*.sublime-* | ||
tmp.js | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
let test_cfg = require('./_integ_test_config.js'); | ||
let should = require('should'); | ||
let path = require('path'); | ||
let BN = require('bn.js'); | ||
let Web3 = require('../'); | ||
|
||
let jarPath = path.join(__dirname, 'contracts', 'Counter.jar') | ||
let web3 = new Web3(new Web3.providers.HttpProvider('https://api.nodesmith.io/v1/aion/avmtestnet/jsonrpc?apiKey=2375791dd8d7455fac3d91a392424277')); | ||
let acc = web3.eth.accounts.privateKeyToAccount(test_cfg.AVM_TEST_PK); | ||
|
||
console.log("Using cfg = ", test_cfg); | ||
console.log("ACC: ", acc.address); | ||
|
||
let tests = [{ | ||
name: 'incrementCounter', | ||
type: 'send', | ||
inputs: 1, | ||
inputTypes: ['int'], | ||
inputValues: [5476545] | ||
}, { | ||
name: 'decrementCounter', | ||
type: 'send', | ||
inputs: 1, | ||
inputTypes: [ 'int' ], | ||
inputValues: [ 300000 ] | ||
}, { | ||
name: 'getCount', | ||
type: 'call', | ||
inputs: 0, | ||
returnType: 'int' | ||
}]; | ||
|
||
// Deploy an AVM Contract | ||
let deploy = async() => { | ||
let data = web3.avm.contract.deploy(jarPath).args([ 'int' ], [ 100 ]).init(); | ||
|
||
//construct a transaction | ||
const txObject = { | ||
from: acc.address, | ||
data: data, | ||
gasPrice: test_cfg.GAS_PRICE, | ||
gas: test_cfg.AVM_TEST_CT_DEPLOY_GAS, | ||
type: '0x2' | ||
}; | ||
|
||
let signedTx = await web3.eth.accounts.signTransaction(txObject, test_cfg.AVM_TEST_PK); | ||
let res = await web3.eth.sendSignedTransaction(signedTx.rawTransaction); | ||
return res; | ||
} | ||
|
||
let methodCallWithInputs = async(methodName, inputTypes, inputValues, returnType) => { | ||
let data = web3.avm.contract.method(methodName).inputs(inputTypes, inputValues).encode(); | ||
|
||
//construct a transaction | ||
const txObject = { | ||
from: acc.address, | ||
to: test_cfg.AVM_TEST_CT_ADDR, | ||
data: data, | ||
gasPrice: test_cfg.GAS_PRICE, | ||
gas: test_cfg.AVM_TEST_CT_TXN_GAS | ||
}; | ||
|
||
let ethRes = await web3.eth.call(txObject); | ||
let avmRes = await web3.avm.contract.decode(returnType, ethRes); | ||
return avmRes; | ||
} | ||
|
||
let methodCallWithoutInputs = async(methodName, returnType) => { | ||
let data = web3.avm.contract.method(methodName).encode(); | ||
|
||
//construct a transaction | ||
const txObject = { | ||
from: acc.address, | ||
to: test_cfg.AVM_TEST_CT_ADDR, | ||
data: data, | ||
gasPrice: test_cfg.GAS_PRICE, | ||
gas: test_cfg.AVM_TEST_CT_TXN_GAS | ||
}; | ||
|
||
let ethRes = await web3.eth.call(txObject); | ||
let avmRes = await web3.avm.contract.decode(returnType, ethRes); | ||
return avmRes; | ||
} | ||
|
||
let methodSendWithInputs = async(methodName, inputTypes, inputValues) => { | ||
let data = web3.avm.contract.method(methodName).inputs(inputTypes, inputValues).encode(); | ||
|
||
//construct a transaction | ||
const txObject = { | ||
from: acc.address, | ||
to: test_cfg.AVM_TEST_CT_ADDR, | ||
data: data, | ||
gasPrice: test_cfg.GAS_PRICE, | ||
gas: test_cfg.AVM_TEST_CT_TXN_GAS, | ||
type: '0x1' | ||
}; | ||
|
||
let signedTx = await web3.eth.accounts.signTransaction(txObject, test_cfg.AVM_TEST_PK); | ||
let res = await web3.eth.sendSignedTransaction(signedTx.rawTransaction); | ||
|
||
|
||
//let unlock = await web3.eth.personal.unlockAccount(test_cfg.TEST_ACCT_ADDR, test_cfg.TEST_ACCT_PW, 6000); | ||
//console.log(unlock); | ||
//let res = await web3.eth.sendTransaction(txObject); | ||
return res; | ||
} | ||
|
||
let methodSendWithoutInputs = async(methodName) => { | ||
let data = web3.avm.contract.method(methodName).encode(); | ||
|
||
//construct a transaction | ||
const txObject = { | ||
from: acc.address, | ||
to: test_cfg.AVM_TEST_CT_ADDR, | ||
data: data, | ||
gasPrice: test_cfg.GAS_PRICE, | ||
gas: test_cfg.AVM_TEST_CT_TXN_GAS, | ||
type: '0x1' | ||
}; | ||
|
||
let unlock = await web3.eth.personal.unlockAccount(test_cfg.TEST_ACCT_ADDR, test_cfg.TEST_ACCT_PW, 600); | ||
let res = await web3.eth.sendTransaction(txObject); | ||
return res; | ||
} | ||
|
||
describe('avm_contract', () => { | ||
|
||
it('deploying contract..', done => { | ||
deploy().then(res => { | ||
test_cfg.AVM_TEST_CT_ADDR = res.contractAddress; | ||
//console.log(JSON.stringify(res)); | ||
res.status.should.eql(true); | ||
done(); | ||
}).catch(err => { | ||
done(err); | ||
}); | ||
}); | ||
|
||
tests.forEach((test) => { | ||
it('testing method, ' + test.name, done => { | ||
if(test.type === 'call') { | ||
if(test.inputs === 1) { | ||
methodCallWithInputs(test.name, test.inputTypes, test.inputValues, test.returnType).then(res => { | ||
done(); | ||
}).catch(err => { | ||
done(err); | ||
}); | ||
} else { | ||
methodCallWithoutInputs(test.name, test.returnType).then(res => { | ||
done(); | ||
}).catch(err => { | ||
done(err); | ||
}); | ||
} | ||
} else if(test.type === 'send') { | ||
if(test.inputs === 1) { | ||
methodSendWithInputs(test.name, test.inputTypes, test.inputValues).then(res => { | ||
done(); | ||
}).catch(err => { | ||
done(err); | ||
}); | ||
} else { | ||
methodSendWithoutInputs(test.name).then(res => { | ||
done(); | ||
}).catch(err => { | ||
done(err); | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
}); |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": "1.1.7", | ||
"version": "1.2.5-beta.2", | ||
"lerna": "2.0.0", | ||
"command": { | ||
"init": { | ||
|
Oops, something went wrong.