-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
134 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"buildInfo": { | ||
"rustc": { | ||
"version": "1.71.0-nightly", | ||
"commitHash": "7f94b314cead7059a71a265a8b64905ef2511796", | ||
"commitDate": "2023-04-23", | ||
"channel": "Nightly", | ||
"short": "rustc 1.71.0-nightly (7f94b314c 2023-04-23)" | ||
}, | ||
"contractCrate": { | ||
"name": "adder", | ||
"version": "0.0.0" | ||
}, | ||
"framework": { | ||
"name": "multiversx-sc", | ||
"version": "0.41.3" | ||
} | ||
}, | ||
"docs": [ | ||
"One of the simplest smart contracts possible,", | ||
"it holds a single variable in storage, which anyone can increment." | ||
], | ||
"name": "Adder", | ||
"constructor": { | ||
"inputs": [ | ||
{ | ||
"name": "initial_value", | ||
"type": "BigUint" | ||
} | ||
], | ||
"outputs": [] | ||
}, | ||
"endpoints": [ | ||
{ | ||
"name": "getSum", | ||
"mutability": "readonly", | ||
"inputs": [], | ||
"outputs": [ | ||
{ | ||
"type": "BigUint" | ||
} | ||
] | ||
}, | ||
{ | ||
"docs": [ | ||
"Add desired amount to the storage variable." | ||
], | ||
"name": "add", | ||
"mutability": "mutable", | ||
"inputs": [ | ||
{ | ||
"name": "value", | ||
"type": "BigUint" | ||
} | ||
], | ||
"outputs": [] | ||
} | ||
], | ||
"events": [], | ||
"hasCallback": false, | ||
"types": {} | ||
} |
Binary file not shown.
60 changes: 60 additions & 0 deletions
60
src/transactionIntentsFactories/smartContractTransactionIntentsFactory.spec.ts
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,60 @@ | ||
import { assert, expect } from "chai"; | ||
import { SmartContractTransactionIntentsFactory } from "./smartContractTransactionIntentsFactory"; | ||
import { Address } from "../address"; | ||
import { Code } from "../smartcontracts/code"; | ||
import { promises } from "fs"; | ||
import { AbiRegistry } from "../smartcontracts/typesystem/abiRegistry"; | ||
import { U32Value } from "../smartcontracts"; | ||
import { CONTRACT_DEPLOY_ADDRESS } from "../constants"; | ||
|
||
describe("test smart contract intents factory", function () { | ||
let smartContractIntentsFactory: SmartContractTransactionIntentsFactory; | ||
let abiSmartContractIntentsFactory: SmartContractTransactionIntentsFactory; | ||
let adderByteCode: Code; | ||
let abiRegistry: AbiRegistry; | ||
|
||
before(async function () { | ||
smartContractIntentsFactory = new SmartContractTransactionIntentsFactory({ chainID: "D", minGasLimit: 50000, gasLimitPerByte: 1500 }); | ||
let adderBuffer = await promises.readFile("src/testdata/adder.wasm"); | ||
adderByteCode = Code.fromBuffer(adderBuffer); | ||
|
||
let abiJson = await promises.readFile("src/testdata/adder.abi.json", { encoding: "utf8" }); | ||
let abiObj = JSON.parse(abiJson); | ||
abiRegistry = AbiRegistry.create(abiObj); | ||
|
||
abiSmartContractIntentsFactory = new SmartContractTransactionIntentsFactory({ chainID: "D", minGasLimit: 50000, gasLimitPerByte: 1500 }, abiRegistry); | ||
}); | ||
|
||
it("should throw error", async function () { | ||
const sender = Address.fromBech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"); | ||
const gasLimit = 6000000; | ||
const args = [0]; | ||
try { | ||
smartContractIntentsFactory.createTransactionIntentForDeploy(sender, adderByteCode.valueOf(), gasLimit, args); | ||
} | ||
catch (err) { | ||
expect(err.message).to.equal("Can't convert args to TypedValues"); | ||
} | ||
}); | ||
|
||
it("should build deploy intent", async function () { | ||
const sender = Address.fromBech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"); | ||
const gasLimit = 6000000; | ||
const args = [new U32Value(0)]; | ||
|
||
const deployIntent = smartContractIntentsFactory.createTransactionIntentForDeploy(sender, adderByteCode.valueOf(), gasLimit, args); | ||
const abiDeployIntent = abiSmartContractIntentsFactory.createTransactionIntentForDeploy(sender, adderByteCode.valueOf(), gasLimit, args); | ||
|
||
assert.equal(deployIntent.sender, "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"); | ||
assert.equal(deployIntent.receiver, CONTRACT_DEPLOY_ADDRESS); | ||
assert.isDefined(deployIntent.data); | ||
|
||
if (deployIntent.data) { | ||
const expectedGasLimit = 6000000 + 50000 + 1500 * deployIntent.data.length; | ||
assert.equal(deployIntent.gasLimit.valueOf(), expectedGasLimit); | ||
} | ||
assert.equal(deployIntent.value, 0); | ||
|
||
assert.deepEqual(deployIntent, abiDeployIntent); | ||
}); | ||
}); |
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