Skip to content

Commit

Permalink
update serialization for parameter Array
Browse files Browse the repository at this point in the history
  • Loading branch information
MickWang committed Nov 22, 2018
1 parent f4a6b6c commit 4282b40
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/transaction/scriptBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const serializeAbiFunction = (abiFunction: AbiFunction) => {
if (list.length > 0) {
list.push(tmp);
}
console.log(JSON.stringify(list));
const result = createCodeParamsScript(list);
return result;
};
Expand All @@ -162,7 +163,7 @@ export function convertArray(list: any[]): any {
} else if (Array.isArray(p)) {
tmp.push(convertArray(p));
} else {
tmp.push(p);
tmp.push(p.getValue ? p.getValue() : p);
}
}
return tmp;
Expand Down
38 changes: 12 additions & 26 deletions test/scParams.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PrivateKey } from '../src/crypto/PrivateKey';
import { RestClient, Struct } from '../src/index';
import { WebsocketClient } from '../src/network/websocket/websocketClient';
import { createCodeParamsScript } from '../src/transaction/scriptBuilder';
import { num2hexstring, reverseHex, str2hexstr } from '../src/utils';
import { Account } from './../src/account';
import { Address } from './../src/crypto/address';
Expand All @@ -14,39 +15,25 @@ describe('test smarct contract params', () => {
const account = Account.create(privateKey, '123456', 'test');
console.log(account.address.serialize());
test('test params Array', async () => {
const contract = reverseHex('f7bafc05ad1fc3822a1db1d195c7dc02959f073e');
const contract = reverseHex('ab01641c418af066402075c78dc8cb8279a7c074');
const contractAddr = new Address(contract);
const method = 'TransferMulti';
const from = new Address('AMxBvXdVasM1WApTS3ViCU9V8hiXYa4437');
const to = new Address('AWyZRDzFp3c53VTLdyD1Z31gB4bUo8ojN4').serialize();
const to2 = new Address('AQGkPm8KqQi4rRbhXX9N6FyjRSawtGwfUf').serialize();
const amount = 100;
const method = 'testHello';

const params = [
new Parameter('op', ParameterType.String, 'test'),
new Parameter('args', ParameterType.Array,
[
from.serialize(),
to,
100
]
),
new Parameter('args', ParameterType.Array,
[
from.serialize(),
to,
100
new Parameter('arg1', ParameterType.Boolean, false),
new Parameter('arg2', ParameterType.Integer, 3),
new Parameter('arg3', ParameterType.ByteArray, account.address.serialize()),
new Parameter('arg4', ParameterType.String, 'arg4')
]
)

];
// const tx = makeInvokeTransaction(method, params, contractAddr, '500', '20000', from);
// const pri = PrivateKey.deserializeWIF('KxRfVFzS6Wm3mAy8h1txuhRzkudN8j2kWAKdjs9FVptCx54HLL7r');
// signTransaction(tx, pri);
// const res = await socketClient.sendRawTransaction(tx.serialize(), false, true);
// console.log(JSON.stringify(res));

const tx = makeInvokeTransaction('BalanceOf', [], contractAddr, '500', '20000');
const res = await socketClient.sendRawTransaction(tx.serialize(), true, false);
const tx = makeInvokeTransaction(method, params, contractAddr, '500', '20000', account.address);
signTransaction(tx, privateKey);
const res = await socketClient.sendRawTransaction(tx.serialize(), false, true);
console.log(JSON.stringify(res));
}, 10000);

Expand All @@ -67,7 +54,7 @@ describe('test smarct contract params', () => {
});

test('fomo3dBuy', async () => {
console.log('hex: ' +str2hexstr(''));
console.log('hex: ' + str2hexstr(''));
const contract = '9361fc1e3a628e1aa46b3d58dde051530f0f5aa0';
const contractAddr = new Address(reverseHex(contract));
const method = 'Buy';
Expand Down Expand Up @@ -116,4 +103,3 @@ describe('test smarct contract params', () => {
}, 10000);

});

8 changes: 6 additions & 2 deletions test/transfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('test transfer asset', () => {
test('test_transfer_asset_ONT', async () => {
const from = adminAddress;
const to = new Address('AH9B261xeBXdKH4jPyafcHcLkS2EKETbUj');
const tx = makeTransferTx('ONT', from, to, 170, gasPrice, gasLimit);
const tx = makeTransferTx('ONT', from, to, 17, gasPrice, gasLimit);
signTransaction(tx, adminPrivateKey);
console.log(tx.payload.serialize());
const response = await socketClient.sendRawTransaction(tx.serialize(), false, true);
Expand Down Expand Up @@ -144,9 +144,13 @@ describe('test transfer asset', () => {
test('test get allowance with tx', async () => {
const from = adminAddress;
const to = new Address('AcprovRtJETffQTFZKEdUrc1tEJebtrPyP');
const tx = makeQueryAllowanceTx('ont', from, to);
const tx = makeQueryAllowanceTx('ong', new Address(ONT_CONTRACT), from);
const result = await restClient.sendRawTransaction(tx.serialize(), true);
console.log(result);
if (result.Result) {
const num = parseInt(reverseHex(result.Result.Result), 16);
console.log(num);
}
expect(result).toBeTruthy();
}, 10000);

Expand Down

0 comments on commit 4282b40

Please sign in to comment.