Skip to content

Commit

Permalink
Merge branch '29-issue-10-own_code_hash'
Browse files Browse the repository at this point in the history
# Conflicts:
#	test-cases/own-code-hash/README.md
  • Loading branch information
Helios-vmg committed Sep 8, 2023
2 parents ef953e7 + b057be9 commit 44e3b32
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test-cases/code-hash/other_contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ e2e-tests = []

[dependencies]
ink = { version = "4.2.1", default-features = false }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "=3.6.5", default-features = false, features = ["derive"] }
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true }

[dev-dependencies]
Expand Down
31 changes: 31 additions & 0 deletions test-cases/own-code-hash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Function `own_code_hash`

```rust
pub fn own_code_hash<E>() -> Result<E::Hash>
```

## Description

Retrieves the code hash of the currently executing contract.

## Related ink! functions

- [`own_code_hash`](https://paritytech.github.io/ink/ink_env/fn.own_code_hash.html)

## Test case

Test case intend to showcase how `own_code_hash` is working in both Integration and End-to-End scenarios. To check the retrieved code hash is correct, we compared it with the code obtained via [`code_hash`](https://paritytech.github.io/ink/ink_env/fn.code_hash.html) by providing the contract `account_id`.

Note in Integration this last step it is not possible due to lack of [`code_hash`](https://paritytech.github.io/ink/ink_env/fn.code_hash.html) implementation, so it is just tested that [`own_code_hash`](https://paritytech.github.io/ink/ink_env/fn.own_code_hash.html) can be called.

| \# | Test | Integration | E2E |
| --- | ------------------------------------------------------- | :---------: | :-: |
| 1 | Attempts to get the code hash of the executing contract |||

## Comparison Integration vs E2E

Test 1 worked as expected in End-to-End but did not on Integration since it's [not implemented](https://github.com/paritytech/ink/blob/c2af39883aab48c71dc09dac5d06583f2e84dc54/crates/env/src/engine/off_chain/impls.rs#L535).

## Result

See estimate for code_hash().

0 comments on commit 44e3b32

Please sign in to comment.