Skip to content

Commit

Permalink
Merge pull request #76 from aionnetwork/avm-support-update
Browse files Browse the repository at this point in the history
Avm support update
  • Loading branch information
K-White authored May 21, 2019
2 parents 457722a + 355fc17 commit 63fe3fa
Show file tree
Hide file tree
Showing 61 changed files with 14,551 additions and 10,389 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ dist/
lerna-debug.log
*.sublime-*
tmp.js
package-lock.json
23 changes: 14 additions & 9 deletions integ_test/_integ_test_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@
*/

let config = {
// Account with which deploy and send Txs (needs to have Aions for tests to work)
TEST_ACCT_ADDR: '',
// Sender account password
TEST_ACCT_PW: '',

// Sender account private key (hex with leading 0x)
TEST_ACCT_PRIVKEY: '',
TEST_ACCT_PRIVKEY: '0xc0a97b1d6d68f3aed19e1d460287efcfd9e93cd294dd86963e08ab24622e4fc6b7dfe3a9fd46fbd034687a6c2a3ddfd61896b8e7521402369383d6a52a591a5b',

// Account with which to receive Txs (No aion will be consumed for tests)
OTHER_TEST_ACCT_ADDR: '',
OTHER_TEST_ACCT_ADDR: '0xa0b88269779d225510ca880ed742e445db0c70efb1ee3159b6d56479ae3501f9',

AVM_TEST_PK: '742b442741b31a93cff3f9c114da4987cac8ec5fbdb1636440a735b307c05041852578c0cd4c5b1b2a39cfc692d064a5ca07c51654052e6f95f9d105e048c808',

TEST_ACCT_PW: 'dbothka%3TH!652#',

TEST_ACCT_ADDR: '0xa021c766c6a9dc565f0240bb833f5f47c94c2591fe7ad5e2dc5b1dc5edceaa40',
// Populate with max gas for transactions (recommended: 4000000)
GAS: 0,
GAS: 4000000,
// Populate with gas price (recommended: 10000000000)
GAS_PRICE: 0,
GAS_PRICE: 10000000000,
AVM_TEST_CT_TXN_GAS: 2000000,
AVM_TEST_CT_DEPLOY_GAS: 5000000,

}
module.exports = function() {
return config;
}();
}();
2 changes: 1 addition & 1 deletion integ_test/abi_encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function deployCt(ct, ctData, args, cb) {
}


describe('contracts', () => {
describe('fvm_contracts', () => {
let opts = {
from: test_cfg.TEST_ACCT_ADDR,
gas: test_cfg.GAS,
Expand Down
173 changes: 173 additions & 0 deletions integ_test/avm_contract.js
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 added integ_test/contracts/Counter.jar
Binary file not shown.
Binary file added integ_test/contracts/Kenroy-1.0-SNAPSHOT.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions integ_test/contract.js → integ_test/fvm_contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function deployCt(ct, ctData, args, cb) {
//.on('confirmation', (confirmationNumber, receipt) => { console.log(confirmationNumber, receipt) });
}

describe('contracts', () => {
describe('fvm_contracts', () => {
let opts = {
from: test_cfg.TEST_ACCT_ADDR,
gas: test_cfg.GAS,
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('contracts', () => {
})


it('contract method call with event', done => {
it('fvm_contract method call with event', done => {
ct.methods.sayHello()
.send({from: test_cfg.TEST_ACCT_ADDR})
.then(res => {
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
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": {
Expand Down
Loading

0 comments on commit 63fe3fa

Please sign in to comment.