-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate the SC Intents Factory in the SmartContract Class #330
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should further discuss about using / not using the exact gas limit provided by the user.
if (bytes.length !== this.codeMetadataLength) { | ||
return new CodeMetadata(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps raising an exception would have worked as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I've done it how it's done in vm-common.
@@ -22,6 +23,22 @@ export class CodeMetadata { | |||
this.payableBySc = payableBySc | |||
} | |||
|
|||
static fromBytes(bytes: Uint8Array): CodeMetadata { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be unit tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added unit test.
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is somehow a behavioral change. I think, in the smart contracts factory, we should simply use the provided gas limit as the "final" one, without adding an extra gas limit for data movement (the computed one). Debatable, though (we should specify this in the specs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, and already done, we are not modifying the gas limit that was set by the user for smart contract transactions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will also fix the unit tests.
@@ -31,7 +31,7 @@ export interface ISmartContract { | |||
export interface DeployArguments { | |||
code: ICode; | |||
codeMetadata?: ICodeMetadata; | |||
initArguments?: TypedValue[]; | |||
initArguments?: any[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Not a breaking change.
@@ -188,7 +188,7 @@ describe("test smart contract interactor", function () { | |||
assert.equal(transaction.getData().toString(), "getUltimateAnswer"); | |||
assert.equal( | |||
transaction.getHash().toString(), | |||
"60d0956a8902c1179dce92d91bd9670e31b9a9cd07c1d620edb7754a315b4818" | |||
"3ff6309bfe87ecc4ab541db649d57187f3a012291570552ac003866f77212c19" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, gas limit should stay the same (and the transaction hashes, as well).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/smartcontracts/smartContract.ts
Outdated
.setCodeMetadata(codeMetadata) | ||
.setInitArgs(initArguments) | ||
.build(); | ||
const bytecode = Uint8Array.from(Buffer.from(code.toString(), 'hex')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const bytecode = Buffer.from(code.toString(), 'hex');
Should have worked, as well, since Buffer
implements Uint8Array
.
@@ -15,16 +15,23 @@ interface Config { | |||
gasLimitPerByte: BigNumber.Value; | |||
} | |||
|
|||
interface Abi { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
const preparedArgs = this.argsToDataParts(args, this.abiRegistry?.constructorDefinition) | ||
const preparedArgs = this.argsToDataParts(args, this.abiRegistry?.getEndpoint(options.functionName)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
const isReadable = options.isReadable || true; | ||
const isPayable = options.isPayable || false; | ||
const isPayableBySmartContract = options.isPayableBySmartContract || true; | ||
const isUpgradeable = options.isUpgradeable ?? true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I see, we should define some constants in the specs, such as:
DEFAULT_CODE_METADATA_IS_READABLE = true;
else { | ||
metadata = new CodeMetadata(); | ||
} | ||
const metadataAsJson = metadata.toJSON() as { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, we can directly make the fields of CodeMetadata
as public readonly
:
https://github.com/multiversx/mx-sdk-js-core/blob/main/src/smartcontracts/codeMetadata.ts
Then use those, without an extra mapping to JSON.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really good if someone uses the toggle...
methods.
Integrated the SC transaction intents factory in the smart contract module.