Skip to content

Fix front end tools error message #142

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

Merged
merged 15 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions front-end-tools/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Unreleased changes

- Fix error message when specifying input parameter without uploading schema.
- Fix error when contract calls return BigInts.
- Fix contract method names in error messages.
- Give warning when deploying a module that does not have embedded build information.

## 3.0.1

- Upgrade dependencies @concordium/web-sdk and @concordium/react-components
Expand Down
2 changes: 2 additions & 0 deletions front-end-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dependencies": {
"@concordium/react-components": "^0.4.0",
"@concordium/web-sdk": "^7.1.0",
"json-bigint": "^1.0.0",
"moment": "^2.29.4",
"react": "^18.1.0",
"react-bootstrap": "^2.7.4",
Expand All @@ -18,6 +19,7 @@
"react-switch": "^7.0.0"
},
"devDependencies": {
"@types/json-bigint": "^1",
"@types/node": "^18.7.23",
"@types/react": "^18.0.9",
"@types/react-dom": "^18.0.5",
Expand Down
4 changes: 2 additions & 2 deletions front-end-tools/src/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ export default function Main(props: ConnectionProps) {
<main className="container">
<div className="textCenter">
<br />
{activeConnectorError && <Alert variant="dager">Connector Error: {activeConnectorError}.</Alert>}
{activeConnectorError && <Alert variant="danger">Connector Error: {activeConnectorError}.</Alert>}
{!activeConnectorError && activeConnectorType && !activeConnector && (
<p>
<i>Loading connector...</i>
</p>
)}
{connectError && <Alert variant="dager">Connect Error: {connectError}.</Alert>}
{connectError && <Alert variant="danger">Connect Error: {connectError}.</Alert>}
{!isConnected && (
<button
className="btn btn-primary me-1"
Expand Down
18 changes: 17 additions & 1 deletion front-end-tools/src/components/DeployComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default function DeployComponenet(props: ConnectionProps) {

const [transactionErrorDeploy, setTransactionErrorDeploy] = useState<string | undefined>(undefined);
const [uploadError, setUploadError] = useState<string | undefined>(undefined);
const [isReproducibleBuild, setIsReproducibleBuild] = useState<boolean | undefined>(undefined);
const [isModuleReferenceAlreadyDeployedStep1, setIsModuleReferenceAlreadyDeployedStep1] = useState(false);
const [txHashDeploy, setTxHashDeploy] = useState<string | undefined>(undefined);
const [base64Module, setBase64Module] = useState<string | undefined>(undefined);
Expand Down Expand Up @@ -131,7 +132,7 @@ export default function DeployComponenet(props: ConnectionProps) {
<Form.Label>Upload Smart Contract Module File (e.g. myContract.wasm.v1)</Form.Label>
<Form.Control
type="file"
accept=".wasm,.wasm.v0,.wasm.v1"
accept=".wasm,.v0,.v1"
{...form.register('file')}
onChange={async (e) => {
const register = form.register('file');
Expand Down Expand Up @@ -220,6 +221,13 @@ export default function DeployComponenet(props: ConnectionProps) {
);

setEmbeddedModuleSchemaBase64Init(moduleSchemaBase64Embedded);

// Check if the module was built as a reproducible build.
const buildInfoSection = WebAssembly.Module.customSections(
wasmModule,
'concordium-build-info'
);
setIsReproducibleBuild(buildInfoSection.length !== 0);
} else {
setUploadError('Upload module file is undefined');
}
Expand All @@ -229,6 +237,14 @@ export default function DeployComponenet(props: ConnectionProps) {
<Form.Text />
</Form.Group>
{uploadError !== undefined && <Alert variant="danger"> Error: {uploadError}. </Alert>}
{isReproducibleBuild === false && (
<Alert variant="warning">
Warning: The module does not have embedded build information. It will likely not be possible to
match this module to source code. See the{' '}
<a href="https://docs.rs/crate/cargo-concordium/latest">cargo-concordium documentation</a> for
more information.
</Alert>
)}
<br />
{base64Module && moduleReferenceCalculated && (
<>
Expand Down
12 changes: 6 additions & 6 deletions front-end-tools/src/components/ReadComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ export default function ReadComponenet(props: ConnectionProps) {
throw new Error('Set smart contract name');
}

let schema = '';

const schemaFromModule = deriveContractInfo ? embeddedModuleSchemaBase64 : uploadedModuleSchemaBase64;

if (schemaFromModule !== undefined) {
schema = schemaFromModule;
const schema = deriveContractInfo ? embeddedModuleSchemaBase64 : uploadedModuleSchemaBase64;
if (schema === undefined) {
setSchemaError(
'Schema was not uploaded or not embedded into the module. Uncheck the "Derive From Smart Contract Index" checkbox to manually upload a schema or uncheck "Has Input Paramter" checkbox if this entrypoint has no input parameter'
);
return;
}

const readFunctionTemplate = getUpdateContractParameterSchema(
Expand Down
12 changes: 6 additions & 6 deletions front-end-tools/src/components/UpdateComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ export default function UpdateComponenet(props: ConnectionProps) {
throw new Error('Set smart contract name');
}

let schema = '';

const schemaFromModule = deriveContractInfo ? embeddedModuleSchemaBase64 : uploadedModuleSchemaBase64;

if (schemaFromModule !== undefined) {
schema = schemaFromModule;
const schema = deriveContractInfo ? embeddedModuleSchemaBase64 : uploadedModuleSchemaBase64;
if (schema === undefined) {
setSchemaError(
'Schema was not uploaded or not embedded into the module. Uncheck the "Derive From Smart Contract Index" checkbox to manually upload a schema or uncheck "Has Input Paramter" checkbox if this entrypoint has no input parameter'
);
return;
}

const functionTemplate = getUpdateContractParameterSchema(
Expand Down
16 changes: 9 additions & 7 deletions front-end-tools/src/reading_from_blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Parameter,
ReturnValue,
} from '@concordium/web-sdk';

import JSONbig from 'json-bigint';
import { CONTRACT_SUB_INDEX } from './constants';

/** This function gets the contract info of a smart contract index. */
Expand Down Expand Up @@ -157,25 +157,27 @@ export async function read(
parameter: param,
});

const fullEntryPointName = `${contractName.value}.${entryPoint.value}`;

if (!res || res.tag === 'failure') {
const rejectReason = JSON.stringify(
((res as InvokeContractFailedResult)?.reason as RejectedReceive)?.rejectReason
);

throw new Error(
`RPC call 'invokeContract' on method '${contractName}.${entryPoint}' of contract '${contractIndex}' failed.
`RPC call 'invokeContract' on method '${fullEntryPointName}' of contract '${contractIndex}' failed.
${rejectReason !== undefined ? `Reject reason: ${rejectReason}` : ''}`
);
}
if (!res.returnValue) {
throw new Error(
`RPC call 'invokeContract' on method '${contractName}.${entryPoint}' of contract '${contractIndex}' returned no return_value`
`RPC call 'invokeContract' on method '${fullEntryPointName}' of contract '${contractIndex}' returned no return_value`
);
}

if (moduleSchema === undefined) {
// If no schema is provided return the raw bytes
return JSON.stringify(res.returnValue);
return JSONbig.stringify(res.returnValue);
}

let returnValue;
Expand All @@ -190,15 +192,15 @@ export async function read(
);
} catch (e) {
throw new Error(
`Deserializing the returnValue from the '${contractName}.${entryPoint}' method of contract '${contractIndex}' failed. Original error: ${e}`
`Deserializing the returnValue from the '${fullEntryPointName}' method of contract '${contractIndex}' failed. Original error: ${e}`
);
}

if (returnValue === undefined) {
throw new Error(
`Deserializing the returnValue from the '${contractName}.${entryPoint}' method of contract '${contractIndex}' failed.`
`Deserializing the returnValue from the '${fullEntryPointName}' method of contract '${contractIndex}' failed.`
);
} else {
return JSON.stringify(returnValue);
return JSONbig.stringify(returnValue);
}
}
9 changes: 9 additions & 0 deletions front-end-tools/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,13 @@ __metadata:
languageName: node
linkType: hard

"@types/json-bigint@npm:^1":
version: 1.0.4
resolution: "@types/json-bigint@npm:1.0.4"
checksum: bb567bac8d64f541abb3cb716d5c699c460b9aa4a9fc5fc81a3cee9cb57fe8c03914022049dcdadff213972979a5d08267405d55d2ed6aa95d3558f08347008a
languageName: node
linkType: hard

"@types/json-schema@npm:^7.0.9":
version: 7.0.15
resolution: "@types/json-schema@npm:7.0.15"
Expand Down Expand Up @@ -3625,6 +3632,7 @@ __metadata:
dependencies:
"@concordium/react-components": "npm:^0.4.0"
"@concordium/web-sdk": "npm:^7.1.0"
"@types/json-bigint": "npm:^1"
"@types/node": "npm:^18.7.23"
"@types/react": "npm:^18.0.9"
"@types/react-dom": "npm:^18.0.5"
Expand All @@ -3640,6 +3648,7 @@ __metadata:
eslint-plugin-jsx-a11y: "npm:^6.5.1"
eslint-plugin-react: "npm:^7.29.4"
eslint-plugin-react-hooks: "npm:^4.4.0"
json-bigint: "npm:^1.0.0"
moment: "npm:^2.29.4"
prettier: "npm:^3.1.0"
process: "npm:^0.11.10"
Expand Down