Skip to content

Commit

Permalink
2942 tez to etherlink (#2944)
Browse files Browse the repository at this point in the history
* feat: add a case to transfer ghostnet tez to etherlink in test-dapp

* style: move the case to top

* feat: updaing desc and naming to Send tez from Ghostnet to Etherlink
  • Loading branch information
hui-an-yang authored May 1, 2024
1 parent 1152b03 commit 8f30cf3
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 deletions.
24 changes: 21 additions & 3 deletions apps/taquito-test-dapp/src/lib/TestContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let loading = false;
let success: boolean | undefined;
let opHash = "";
let input = { text: "", fee: 400, storageLimit: 400, gasLimit: 1320 };
let input = { text: "", fee: 400, storageLimit: 400, gasLimit: 1320, amount: 0, address: "" };
let testResult: { id: string; title: string; body: any };
const run = async () => {
Expand All @@ -28,6 +28,7 @@
test.id === "sign-payload-and-send" ||
test.id === "sign-failingNoop" ||
test.id === "verify-signature" ||
test.id === "send-tez-to-etherlink" ||
test.id === "set-transaction-limits"
) {
result = await test.run(input);
Expand Down Expand Up @@ -188,7 +189,7 @@
/* ----------------------------------------------
* Generated by Animista on 2022-4-21 9:31:8
* Licensed under FreeBSD License.
* See http://animista.net/license for more info.
* See http://animista.net/license for more info.
* w: http://animista.net, t: @cssanimista
* ---------------------------------------------- */
Expand Down Expand Up @@ -302,6 +303,19 @@
bind:value={input.text}
/>
</div>
{:else if test.inputRequired && test.inputType === "etherlink"}
<div class="test-input test-send-tez-to-etherlink">
<label for="etherlink-address">
<span>Etherlink address</span>
<input type="string" id="etherlink-address" bind:value={input.address} />
</label>
<br />
<br />
<label for="send-amount">
<span>amount</span>
<input type="number" id="send-amount" bind:value={input.amount} />
</label>
</div>
{:else if test.inputRequired && test.inputType === "set-limits"}
<div class="test-input test-limits">
<label for="set-limit-fee">
Expand Down Expand Up @@ -338,7 +352,11 @@
{#if $store.networkType === NetworkType.CUSTOM}
{shortenHash(opHash)}
{:else}
<a href={`${getTzKtUrl($store.networkType)}/${opHash}`} target="_blank" rel="noopener noreferrer">
<a
href={`${getTzKtUrl($store.networkType)}/${opHash}`}
target="_blank"
rel="noopener noreferrer"
>
{shortenHash(opHash)}
</a>
{/if}
Expand Down
42 changes: 40 additions & 2 deletions apps/taquito-test-dapp/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ const preparePayloadToSign = (
};
};

const sendTezToEtherlink = async (
amount: number,
address: string,
tezos: TezosToolkit,
): Promise<TestResult> => {
let opHash = "";
try {
const contract = await tezos.wallet.at('KT1VEjeQfDBSfpDH5WeBM5LukHPGM2htYEh3')
let op = await contract.methodsObject.deposit({ evm_address: 'sr18wx6ezkeRjt1SZSeZ2UQzQN3Uc3YLMLqg', l2_address: address }).send({ amount });
await op.confirmation()
opHash = op.hasOwnProperty("opHash") ? op["opHash"] : op["hash"];
console.log("Operation successful with op hash:", opHash);
return { success: true, opHash };
} catch (error) {
console.log(error);
return { success: false, opHash: "" };
}
};

const sendTez = async (Tezos: TezosToolkit): Promise<TestResult> => {
let opHash = "";
try {
Expand Down Expand Up @@ -302,7 +321,7 @@ const signPayloadAndSend = async (
const publicKey = activeAccount.publicKey;
// sends transaction to contract
const op = await contract.methodsObject
.check_signature({0: publicKey, 1: signedPayload.signature, 2: payload.payload})
.check_signature({ 0: publicKey, 1: signedPayload.signature, 2: payload.payload })
.send();
await op.confirmation();
return {
Expand Down Expand Up @@ -455,7 +474,7 @@ const permit = async (Tezos: TezosToolkit, wallet: BeaconWallet) => {
const contract = await Tezos.wallet.at(contractAddress);
// hashes the parameter for the contract call
const mintParam: any = contract.methodsObject
.mint({0: store.userAddress, 1: 100})
.mint({ 0: store.userAddress, 1: 100 })
.toTransferParams().parameter?.value;
const mintParamType = contract.entrypoints.entrypoints["mint"];
// packs the entrypoint call
Expand Down Expand Up @@ -548,6 +567,7 @@ const saplingShielded = async (

export const list = [
"Send tez",
"Send tez from Ghostnet to Etherlink",
"Contract call with int",
"Contract call with (pair nat string)",
"Contract call that fails",
Expand Down Expand Up @@ -582,6 +602,24 @@ export const init = (
inputRequired: false,
lastResult: { option: "none", val: false }
},
{
id: "send-tez-to-etherlink",
name: "Send tez from Ghostnet to Etherlink",
description:
"This test allows you send your ghostnet tez to etherlink address",
documentation: '',
keyword: 'etherlink',
run: input =>
sendTezToEtherlink(
input.amount,
input.address,
Tezos
),
showExecutionTime: false,
inputRequired: true,
inputType: "etherlink",
lastResult: { option: "none", val: false }
},
{
id: "contract-call-simple-type",
name: "Contract call with int",
Expand Down
2 changes: 1 addition & 1 deletion apps/taquito-test-dapp/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface TestSettings {
run: (input?: any) => Promise<TestResult>;
showExecutionTime: boolean;
inputRequired: boolean;
inputType?: "string" | "set-limits" | "sapling";
inputType?: "string" | "set-limits" | "sapling" | "etherlink";
lastResult: { option: "none" | "some"; val: boolean };
}

Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"edsk",
"Ejara",
"entrypoints",
"etherlink",
"eztz",
"FAILWITH",
"flextesa",
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"example:scan-path-ledger": "node -r ts-node/register --preserve-symlinks scan-path-ledger.ts"
},
"dependencies": {
"@ledgerhq/hw-transport-node-hid": "^6.27.21",
"@ledgerhq/hw-transport-node-hid": "^6.28.5",
"@taquito/ledger-signer": "^19.2.0",
"@taquito/local-forging": "^19.2.0",
"@taquito/michel-codec": "^19.2.0",
Expand Down

0 comments on commit 8f30cf3

Please sign in to comment.