Skip to content
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

feat: implement predicates/scripts CLI deploy #3254

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion nodemon.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"**/out/release/**",
"apps/demo-typegen/src/contract-types/**",
"apps/demo-typegen/src/predicate-types/**",
"apps/demo-typegen/src/script-types/**"
"apps/demo-typegen/src/script-types/**",
"packages/fuels/src/cli/commands/deploy/proxy/types/**"
]
}
12 changes: 8 additions & 4 deletions packages/contract/src/contract-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,20 @@
return { waitForResult, contractId, waitForTransactionId };
}

async deployAsBlobTxForScript(configurableConstants: { [name: string]: unknown } = {}): Promise<{

Check warning on line 379 in packages/contract/src/contract-factory.ts

View workflow job for this annotation

GitHub Actions / Lint

'configurableConstants' is assigned a value but never used
waitForResult: () => Promise<{
transactionResult: TransactionResult<TransactionType.Blob>;
loaderBytecode: string;
}>;
blobId: string;
loaderBytecode: string;
}> {
const account = this.getAccount();
if (configurableConstants) {
this.setConfigurableConstants(configurableConstants);
}

// TODO: We think that we should not be setting configurable constants here, but rather when we try to call the script.
// if (configurableConstants) {
// this.setConfigurableConstants(configurableConstants);
// }

// Generate the associated create tx for the loader contract
const blobId = hash(this.bytecode);
Expand Down Expand Up @@ -444,7 +448,7 @@
return { transactionResult: result, loaderBytecode: hexlify(loaderBytecode) };
};

return { waitForResult };
return { waitForResult, blobId, loaderBytecode: hexlify(loaderBytecode) };
}

/**
Expand Down
55 changes: 17 additions & 38 deletions packages/fuels/src/cli/commands/deploy/deployScripts.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import type { WalletUnlocked } from '@fuel-ts/account';
import type { DeployContractOptions } from '@fuel-ts/contract';
import { ContractFactory } from '@fuel-ts/contract';
import { debug, log } from 'console';
import { readFileSync } from 'fs';

import type { ForcToml } from '../../config/forcUtils';
import {
getClosestForcTomlDir,
getBinaryPath,
getABIPath,
getStorageSlotsPath,
getContractName,
readForcToml,
} from '../../config/forcUtils';
import { getBinaryPath, getABIPath, getContractName } from '../../config/forcUtils';
import type { FuelsConfig, DeployedScript } from '../../types';

import { createWallet } from './createWallet';
Expand All @@ -21,24 +16,22 @@
wallet: WalletUnlocked,
binaryPath: string,
abiPath: string,
storageSlotsPath: string,
scriptPath: string,
tomlContents: ForcToml
configurableConstants?: DeployContractOptions['configurableConstants']
) {
debug(`Deploying script for ABI: ${abiPath}`);

// Implement script deploy
await Promise.resolve({
wallet,
binaryPath,
abiPath,
storageSlotsPath,
scriptPath,
tomlContents,
});
const bytecode = readFileSync(binaryPath);
const abi = JSON.parse(readFileSync(abiPath, 'utf-8'));
const factory = new ContractFactory(bytecode, abi, wallet);

// TODO: implement me
return 'deployed-blob-id';
const { waitForResult, blobId, loaderBytecode } =
await factory.deployAsBlobTxForScript(configurableConstants);
await waitForResult();

return {
blobId,
loaderBytecode,
};
}

/**
Expand All @@ -53,27 +46,13 @@

const scriptsLen = config.scripts.length;

for (let i = 0; i < scriptsLen; i++) {

Check failure on line 49 in packages/fuels/src/cli/commands/deploy/deployScripts.ts

View workflow job for this annotation

GitHub Actions / node@18

packages/fuels/src/cli/commands/deploy/index.test.ts > deploy > should call onDeploy callback

Error: ENOENT: no such file or directory, open '/home/runner/work/fuels-ts/fuels-ts/packages/fuels/test/fixtures/workspace/scripts/script/out/debug/script-true.bin' ❯ deployScript packages/fuels/src/cli/commands/deploy/deployScripts.ts:49:19 ❯ Module.deployScripts packages/fuels/src/cli/commands/deploy/deployScripts.ts:370:42 ❯ Module.deploy packages/fuels/src/cli/commands/deploy/index.ts:148:45 ❯ packages/fuels/src/cli/commands/deploy/index.test.ts:37:5 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, syscall: 'open', code: 'ENOENT', path: '/home/runner/work/fuels-ts/fuels-ts/packages/fuels/test/fixtures/workspace/scripts/script/out/debug/script-true.bin' }

Check failure on line 49 in packages/fuels/src/cli/commands/deploy/deployScripts.ts

View workflow job for this annotation

GitHub Actions / node@20

packages/fuels/src/cli/commands/deploy/index.test.ts > deploy > should call onDeploy callback

Error: ENOENT: no such file or directory, open '/home/runner/work/fuels-ts/fuels-ts/packages/fuels/test/fixtures/workspace/scripts/script/out/debug/script-true.bin' ❯ deployScript packages/fuels/src/cli/commands/deploy/deployScripts.ts:49:19 ❯ Module.deployScripts packages/fuels/src/cli/commands/deploy/deployScripts.ts:370:42 ❯ Module.deploy packages/fuels/src/cli/commands/deploy/index.ts:148:45 ❯ packages/fuels/src/cli/commands/deploy/index.test.ts:37:5 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/fuels-ts/fuels-ts/packages/fuels/test/fixtures/workspace/scripts/script/out/debug/script-true.bin' }

Check failure on line 49 in packages/fuels/src/cli/commands/deploy/deployScripts.ts

View workflow job for this annotation

GitHub Actions / node@22

packages/fuels/src/cli/commands/deploy/index.test.ts > deploy > should call onDeploy callback

Error: ENOENT: no such file or directory, open '/home/runner/work/fuels-ts/fuels-ts/packages/fuels/test/fixtures/workspace/scripts/script/out/debug/script-true.bin' ❯ deployScript packages/fuels/src/cli/commands/deploy/deployScripts.ts:49:19 ❯ Module.deployScripts packages/fuels/src/cli/commands/deploy/deployScripts.ts:370:42 ❯ Module.deploy packages/fuels/src/cli/commands/deploy/index.ts:148:45 ❯ packages/fuels/src/cli/commands/deploy/index.test.ts:37:5 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/runner/work/fuels-ts/fuels-ts/packages/fuels/test/fixtures/workspace/scripts/script/out/debug/script-true.bin' }
const scriptPath = config.scripts[i];
const forcTomlPath = getClosestForcTomlDir(scriptPath);
const binaryPath = getBinaryPath(scriptPath, config);
const abiPath = getABIPath(scriptPath, config);
const storageSlotsPath = getStorageSlotsPath(scriptPath, config);
const projectName = getContractName(scriptPath);
// const scriptName = getContractCamelCase(scriptPath);
const tomlContents = readForcToml(forcTomlPath);

const blobId = await deployScript(
wallet,
binaryPath,
abiPath,
storageSlotsPath,
scriptPath,
tomlContents
);

// TODO: implement me
const loaderBytecode = `0x${blobId}`;
const { blobId, loaderBytecode } = await deployScript(wallet, binaryPath, abiPath);

debug(`Script deployed: ${projectName} - ${blobId}`);

Expand Down
2 changes: 1 addition & 1 deletion packages/fuels/src/cli/commands/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* After saving the script files, we need to
* re-generate types for them.
*
* This time, the script will have to binaries:
* This time, the script will have two binaries:
* - the original one
* - the loader one (after deploy)
*
Expand All @@ -32,7 +32,7 @@
*
* This would look like:
*
* import { MyScript, MyScriptDeployed } from './generated-types';

Check warning on line 35 in packages/fuels/src/cli/commands/deploy/index.ts

View workflow job for this annotation

GitHub Actions / Lint

tsdoc-malformed-inline-tag: Expecting a TSDoc tag starting with "{@"

Check warning on line 35 in packages/fuels/src/cli/commands/deploy/index.ts

View workflow job for this annotation

GitHub Actions / Lint

tsdoc-escape-right-brace: The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
*
*/

Expand Down
Loading