Skip to content

Commit

Permalink
integrate sc intents factory
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Sep 13, 2023
1 parent 19a643e commit 48ee428
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/smartcontracts/interaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("test smart contract interactor", function () {
assert.deepEqual(transaction.getReceiver(), dummyAddress);
assert.equal(transaction.getValue().toString(), "1000000000000000000");
assert.equal(transaction.getNonce(), 7);
assert.equal(transaction.getGasLimit().valueOf(), 20000000);
assert.equal(transaction.getGasLimit().valueOf(), 20057500);
});

it("should set transfers (payments) on contract calls (transfer and execute)", async function () {
Expand Down Expand Up @@ -188,7 +188,7 @@ describe("test smart contract interactor", function () {
assert.equal(transaction.getData().toString(), "getUltimateAnswer");
assert.equal(
transaction.getHash().toString(),
"60d0956a8902c1179dce92d91bd9670e31b9a9cd07c1d620edb7754a315b4818"
"3ff6309bfe87ecc4ab541db649d57187f3a012291570552ac003866f77212c19"
);

transaction = interaction.withNonce(1).buildTransaction();
Expand All @@ -198,7 +198,7 @@ describe("test smart contract interactor", function () {
assert.equal(transaction.getNonce().valueOf(), 1);
assert.equal(
transaction.getHash().toString(),
"acd207c38f6c3341b18d8ef331fa07ba49615fa12d7610aad5d8495293049f24"
"85a3044ba2e07317a7e5dd866a5e57f900f7e01d0802c8cd634f4a521261dadf"
);

// Execute, and wait for execution
Expand Down
6 changes: 3 additions & 3 deletions src/smartcontracts/smartContract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ describe("test contract", () => {

assert.equal(callTransactionOne.getNonce().valueOf(), 42);
assert.equal(callTransactionOne.getData().valueOf().toString(), "helloEarth@05@0123");
assert.equal(callTransactionOne.getGasLimit().valueOf(), 150000);
assert.equal(callTransactionOne.getGasLimit().valueOf(), 227000);
assert.equal(callTransactionTwo.getNonce().valueOf(), 43);
assert.equal(callTransactionTwo.getData().valueOf().toString(), "helloMars@05@0123");
assert.equal(callTransactionTwo.getGasLimit().valueOf(), 1500000);
assert.equal(callTransactionTwo.getGasLimit().valueOf(), 1575500);

// Sign transactions, broadcast them
alice.signer.sign(callTransactionOne);
Expand All @@ -126,7 +126,7 @@ describe("test contract", () => {
assert.isTrue((await provider.getTransactionStatus(hashTwo)).isExecuted());
});

it.only("should upgrade", async () => {
it("should upgrade", async () => {
setupUnitTestWatcherTimeouts();
let watcher = new TransactionWatcher(provider);

Expand Down
31 changes: 19 additions & 12 deletions src/smartcontracts/smartContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ export class SmartContract implements ISmartContract {
})

return new Transaction({
receiver: Address.fromBech32(intent.receiver),
sender: Address.fromBech32(intent.sender),
receiver: Address.fromBech32(intent.receiver),
value: value,
gasLimit: new BigNumber(intent.gasLimit).toNumber(),
gasPrice: gasPrice,
Expand All @@ -217,25 +217,32 @@ export class SmartContract implements ISmartContract {

this.ensureHasAddress();

const config = new TransactionIntentsFactoryConfig(chainID.valueOf());
const scIntentFactory = new SmartContractTransactionIntentsFactory({
config: config,
abi: this.abi
});

args = args || [];
value = value || 0;

let payload = new ContractCallPayloadBuilder()
.setFunction(func)
.setArgs(args)
.build();
const intent = scIntentFactory.createTransactionIntentForExecute({
sender: caller,
contractAddress: receiver ? receiver : this.getAddress(),
functionName: func.toString(),
gasLimit: gasLimit.valueOf(),
args: args
})

let transaction = new Transaction({
return new Transaction({
sender: caller,
receiver: receiver ? receiver : this.getAddress(),
receiver: Address.fromBech32(intent.receiver),
value: value,
gasLimit: gasLimit,
gasLimit: new BigNumber(intent.gasLimit).toNumber(),
gasPrice: gasPrice,
data: payload,
chainID: chainID,
data: new TransactionPayload(Buffer.from(intent.data!)),
chainID: chainID
});

return transaction;
}

createQuery({ func, args, value, caller }: QueryArguments): Query {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ describe("test smart contract intents factory", function () {
const deployIntent = factory.createTransactionIntentForExecute({
sender: sender,
contractAddress: contract,
func: func,
functionName: func,
gasLimit: gasLimit,
args: args
});
const abiDeployIntent = abiAwareFactory.createTransactionIntentForExecute({
sender: sender,
contractAddress: contract,
func: func,
functionName: func,
gasLimit: gasLimit,
args: args
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ export class SmartContractTransactionIntentsFactory {
createTransactionIntentForExecute(options: {
sender: IAddress,
contractAddress: IAddress,
func: string,
functionName: string,
gasLimit: BigNumber.Value,
args?: any[]
}
): TransactionIntent {
const args = options.args || [];
let parts: string[] = [options.func];
let parts: string[] = [options.functionName];

const preparedArgs = this.argsToDataParts(args, this.abiRegistry?.constructorDefinition)
const preparedArgs = this.argsToDataParts(args, this.abiRegistry?.getEndpoint(options.functionName));
parts = parts.concat(preparedArgs);

return new TransactionIntentBuilder({
Expand Down

0 comments on commit 48ee428

Please sign in to comment.