-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: handling and externalisation improvements for account nonce …
…updates (#2176) * chore: all necessary stuff for release Signed-off-by: svetoslav-nikol0v <[email protected]> * feature: add signerNonce field Signed-off-by: svetoslav-nikol0v <[email protected]> --------- Signed-off-by: svetoslav-nikol0v <[email protected]>
- Loading branch information
1 parent
ff2a699
commit a58be38
Showing
10 changed files
with
241 additions
and
12 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { | ||
FileCreateTransaction, | ||
ContractFunctionParameters, | ||
ContractCreateTransaction, | ||
EthereumTransaction, | ||
PrivateKey, | ||
TransferTransaction, | ||
Hbar, | ||
TransactionResponse, | ||
TransactionReceipt, | ||
FileId, | ||
ContractId, | ||
Status, | ||
TransactionRecord, | ||
} from "../../src/exports.js"; | ||
import { SMART_CONTRACT_BYTECODE } from "./contents.js"; | ||
import * as rlp from "@ethersproject/rlp"; | ||
import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js"; | ||
import * as hex from "../../src/encoding/hex.js"; | ||
|
||
describe.only("EthereumTransactionIntegrationTest", function () { | ||
Check warning on line 21 in test/integration/EthereumTransactionIntegrationTest.js GitHub Actions / Integration Tests on Node 16
Check warning on line 21 in test/integration/EthereumTransactionIntegrationTest.js GitHub Actions / Integration Tests on Node 18
Check warning on line 21 in test/integration/EthereumTransactionIntegrationTest.js GitHub Actions / Build using Node 16
Check warning on line 21 in test/integration/EthereumTransactionIntegrationTest.js GitHub Actions / Build using Node 18
|
||
let env, operatorKey, wallet, contractAddress, operatorId; | ||
|
||
before(async function () { | ||
env = await IntegrationTestEnv.new(); | ||
wallet = env.wallet; | ||
operatorKey = wallet.getAccountKey(); | ||
operatorId = wallet.getAccountId(); | ||
}); | ||
|
||
it("Signer nonce changed on Ethereum transaction", async function () { | ||
this.timeout(120000); | ||
|
||
try { | ||
const fileResponse = await ( | ||
await ( | ||
await new FileCreateTransaction() | ||
.setKeys([wallet.getAccountKey()]) | ||
.setContents(SMART_CONTRACT_BYTECODE) | ||
.setMaxTransactionFee(new Hbar(2)) | ||
.freezeWithSigner(wallet) | ||
).signWithSigner(wallet) | ||
).executeWithSigner(wallet); | ||
expect(fileResponse).to.be.instanceof(TransactionResponse); | ||
|
||
const fileReceipt = await fileResponse.getReceiptWithSigner(wallet); | ||
expect(fileReceipt).to.be.instanceof(TransactionReceipt); | ||
expect(fileReceipt.status).to.be.equal(Status.Success); | ||
const fileId = fileReceipt.fileId; | ||
expect(fileId).to.be.instanceof(FileId); | ||
|
||
const contractResponse = await ( | ||
await ( | ||
await new ContractCreateTransaction() | ||
.setAdminKey(operatorKey) | ||
.setGas(200000) | ||
.setConstructorParameters( | ||
new ContractFunctionParameters() | ||
.addString("Hello from Hedera.") | ||
._build(), | ||
) | ||
.setBytecodeFileId(fileId) | ||
.setContractMemo("[e2e::ContractCreateTransaction]") | ||
.freezeWithSigner(wallet) | ||
).signWithSigner(wallet) | ||
).executeWithSigner(wallet); | ||
expect(contractResponse).to.be.instanceof(TransactionResponse); | ||
const contractReceipt = | ||
await contractResponse.getReceiptWithSigner(wallet); | ||
expect(contractReceipt).to.be.instanceof(TransactionReceipt); | ||
expect(contractReceipt.status).to.be.equal(Status.Success); | ||
const contractId = contractReceipt.contractId; | ||
expect(contractId).to.be.instanceof(ContractId); | ||
contractAddress = contractId.toSolidityAddress(); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
|
||
const type = "02"; | ||
const chainId = hex.decode("012a"); | ||
const nonce = new Uint8Array(); | ||
const maxPriorityGas = hex.decode("00"); | ||
const maxGas = hex.decode("d1385c7bf0"); | ||
const gasLimit = hex.decode("0249f0"); | ||
const value = new Uint8Array(); | ||
const to = hex.decode(contractAddress); | ||
const callData = new ContractFunctionParameters() | ||
.addString("new message") | ||
._build("setMessage"); | ||
const accessList = []; | ||
|
||
const encoded = rlp | ||
.encode([ | ||
chainId, | ||
nonce, | ||
maxPriorityGas, | ||
maxGas, | ||
gasLimit, | ||
to, | ||
value, | ||
callData, | ||
accessList, | ||
]) | ||
.substring(2); | ||
expect(typeof encoded).to.equal("string"); | ||
|
||
const privateKey = PrivateKey.generateECDSA(); | ||
expect(privateKey).to.be.instanceof(PrivateKey); | ||
|
||
const accountAlias = privateKey.publicKey.toEvmAddress(); | ||
|
||
const transfer = await new TransferTransaction() | ||
.addHbarTransfer(operatorId, new Hbar(10).negated()) | ||
.addHbarTransfer(accountAlias, new Hbar(10)) | ||
.setMaxTransactionFee(new Hbar(1)) | ||
.freezeWithSigner(wallet); | ||
|
||
const transferResponse = await transfer.executeWithSigner(wallet); | ||
expect(transferResponse).to.be.instanceof(TransactionResponse); | ||
const transferReceipt = | ||
await transferResponse.getReceiptWithSigner(wallet); | ||
expect(transferReceipt).to.be.instanceof(TransactionReceipt); | ||
expect(transferReceipt.status).to.be.equal(Status.Success); | ||
|
||
const signedBytes = privateKey.sign(hex.decode(type + encoded)); | ||
const middleOfSignedBytes = signedBytes.length / 2; | ||
const r = signedBytes.slice(0, middleOfSignedBytes); | ||
const s = signedBytes.slice(middleOfSignedBytes, signedBytes.length); | ||
const v = hex.decode("01"); // recovery id | ||
|
||
const data = rlp | ||
.encode([ | ||
chainId, | ||
nonce, | ||
maxPriorityGas, | ||
maxGas, | ||
gasLimit, | ||
to, | ||
value, | ||
callData, | ||
accessList, | ||
v, | ||
r, | ||
s, | ||
]) | ||
.substring(2); | ||
expect(typeof data).to.equal("string"); | ||
const ethereumData = hex.decode(type + data); | ||
expect(ethereumData.length).to.be.gt(0); | ||
|
||
const response = await ( | ||
await ( | ||
await new EthereumTransaction() | ||
.setEthereumData(ethereumData) | ||
.freezeWithSigner(wallet) | ||
).signWithSigner(wallet) | ||
).executeWithSigner(wallet); | ||
const record = await response.getRecordWithSigner(wallet); | ||
expect(record).to.be.instanceof(TransactionRecord); | ||
expect(response).to.be.instanceof(TransactionResponse); | ||
|
||
const receipt = await response.getReceiptWithSigner(wallet); | ||
expect(receipt).to.be.instanceof(TransactionReceipt); | ||
expect(receipt.status).to.be.equal(Status.Success); | ||
}); | ||
}); |
Oops, something went wrong.