Skip to content

update contracts to v2.2.0 #592

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 6 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:
docker:
# The audit tool might use a more modern Rust version than the build jobs. See
# "Tooling Rust compiler" in docs/COMPILER_VERSIONS.md
- image: cimg/rust:1.81.0
- image: cimg/rust:1.83.0
steps:
- checkout
- run:
Expand All @@ -152,8 +152,8 @@ jobs:
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- v3-libwasmvm_audit-rust:1.81.0-{{ checksum "libwasmvm/Cargo.lock" }}
- v3-libwasmvm_audit-rust:1.81.0-
- v3-libwasmvm_audit-rust:1.83.0-{{ checksum "libwasmvm/Cargo.lock" }}
- v3-libwasmvm_audit-rust:1.83.0-
- run:
name: Install cargo-audit
command: cargo install --debug cargo-audit --version 0.21.0 --locked
Expand All @@ -164,7 +164,7 @@ jobs:
- save_cache:
paths:
- ~/.cargo/registry
key: v3-libwasmvm_audit-rust:1.81.0-{{ checksum "libwasmvm/Cargo.lock" }}
key: v3-libwasmvm_audit-rust:1.83.0-{{ checksum "libwasmvm/Cargo.lock" }}

format-go:
docker:
Expand Down Expand Up @@ -267,8 +267,7 @@ jobs:

build_shared_library:
docker:
# libwasmvm versions built with 1.81 are broken, so we use 1.82 here
- image: cimg/rust:1.82.0
- image: cimg/rust:1.83.0
steps:
- checkout
- run:
Expand Down Expand Up @@ -456,7 +455,7 @@ workflows:
matrix:
parameters:
# Run with MSRV and some modern stable Rust
rust-version: ["1.81.0", "1.82.0"]
rust-version: ["1.82.0", "1.83.0"]
- libwasmvm_audit
- format-go
- wasmvm_no_cgo
Expand Down
8 changes: 4 additions & 4 deletions ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func TestIBCPacketDispatch(t *testing.T) {
var ack2 AcknowledgeDispatch
err = json.Unmarshal(prResponse2.Acknowledgement, &ack2)
require.NoError(t, err)
require.Equal(t, "invalid packet: cosmwasm_std::addresses::Addr not found", ack2.Err)
require.Equal(t, "invalid packet: account no-such-channel not found", ack2.Err)

// check for the expected custom event
expected_events := []types.Event{{
Expand All @@ -302,8 +302,8 @@ func TestAnalyzeCode(t *testing.T) {
report, err := vm.AnalyzeCode(checksum)
require.NoError(t, err)
require.False(t, report.HasIBCEntryPoints)
require.Equal(t, "", report.RequiredCapabilities)
require.Equal(t, uint64(42), *report.ContractMigrateVersion)
require.Equal(t, "cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0,cosmwasm_2_1,cosmwasm_2_2", report.RequiredCapabilities)
require.Equal(t, uint64(0x1a4), *report.ContractMigrateVersion)

// Store IBC contract
wasm2, err := os.ReadFile(IBC_TEST_CONTRACT)
Expand All @@ -314,7 +314,7 @@ func TestAnalyzeCode(t *testing.T) {
report2, err := vm.AnalyzeCode(checksum2)
require.NoError(t, err)
require.True(t, report2.HasIBCEntryPoints)
require.Equal(t, "iterator,stargate", report2.RequiredCapabilities)
require.Equal(t, "cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0,cosmwasm_2_1,cosmwasm_2_2,iterator,stargate", report2.RequiredCapabilities)
require.Nil(t, report2.ContractMigrateVersion)
}

Expand Down
19 changes: 10 additions & 9 deletions internal/api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
TESTING_CACHE_SIZE = 100 // MiB
)

var TESTING_CAPABILITIES = []string{"staking", "stargate", "iterator", "cosmwasm_1_1", "cosmwasm_1_2", "cosmwasm_1_3"}
var TESTING_CAPABILITIES = []string{"staking", "stargate", "iterator", "cosmwasm_1_1", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "cosmwasm_2_0", "cosmwasm_2_1", "cosmwasm_2_2"}

func TestInitAndReleaseCache(t *testing.T) {
tmpdir, err := os.MkdirTemp("", "wasmvm-testing")
Expand Down Expand Up @@ -694,7 +694,8 @@ func TestExecutePanic(t *testing.T) {
store.SetGasMeter(gasMeter2)
info = MockInfoBin(t, "fred")
_, _, err = Execute(cache, checksum, env, info, []byte(`{"panic":{}}`), &igasMeter2, store, api, &querier, maxGas, TESTING_PRINT_DEBUG)
require.ErrorContains(t, err, "RuntimeError: Aborted: panicked at 'This page intentionally faulted'")
require.Error(t, err)
require.Contains(t, err.Error(), "RuntimeError: Aborted: panicked at src/contract.rs:127:5:\nThis page intentionally faulted")
}

func TestExecuteUnreachable(t *testing.T) {
Expand Down Expand Up @@ -958,7 +959,8 @@ func TestMigrate(t *testing.T) {

// migrate to a new verifier - alice
// we use the same code blob as we are testing hackatom self-migration
_, _, err = Migrate(cache, checksum, env, []byte(`{"verifier":"alice"}`), &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
info = MockInfoBin(t, "admin")
_, _, err = MigrateWithInfo(cache, checksum, env, []byte(`{"verifier":"alice"}`), info, &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
require.NoError(t, err)

// should update verifier to alice
Expand Down Expand Up @@ -988,8 +990,7 @@ func TestMultipleInstances(t *testing.T) {
res, cost, err := Instantiate(cache, checksum, env, info, msg, &igasMeter1, store1, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
require.NoError(t, err)
requireOkResponse(t, res, 0)
// we now count wasm gas charges and db writes
assert.Equal(t, uint64(0xb0c2cd), cost.UsedInternally)
assert.Equal(t, uint64(0xa2aeb8), cost.UsedInternally)

// instance2 controlled by mary
gasMeter2 := NewMockGasMeter(TESTING_GAS_LIMIT)
Expand All @@ -1000,14 +1001,14 @@ func TestMultipleInstances(t *testing.T) {
res, cost, err = Instantiate(cache, checksum, env, info, msg, &igasMeter2, store2, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
require.NoError(t, err)
requireOkResponse(t, res, 0)
assert.Equal(t, uint64(0xb1760a), cost.UsedInternally)
assert.Equal(t, uint64(0xa35f43), cost.UsedInternally)

// fail to execute store1 with mary
resp := exec(t, cache, checksum, "mary", store1, api, querier, 0xa7c5ce)
resp := exec(t, cache, checksum, "mary", store1, api, querier, 0x9a2b03)
require.Equal(t, "Unauthorized", resp.Err)

// succeed to execute store1 with fred
resp = exec(t, cache, checksum, "fred", store1, api, querier, 0x140e8ad)
resp = exec(t, cache, checksum, "fred", store1, api, querier, 0x1281a12)
require.Equal(t, "", resp.Err)
require.Len(t, resp.Ok.Messages, 1)
attributes := resp.Ok.Attributes
Expand All @@ -1016,7 +1017,7 @@ func TestMultipleInstances(t *testing.T) {
require.Equal(t, "bob", attributes[1].Value)

// succeed to execute store2 with mary
resp = exec(t, cache, checksum, "mary", store2, api, querier, 0x1412b29)
resp = exec(t, cache, checksum, "mary", store2, api, querier, 0x12859dc)
require.Equal(t, "", resp.Err)
require.Len(t, resp.Ok.Messages, 1)
attributes = resp.Ok.Attributes
Expand Down
2 changes: 1 addition & 1 deletion lib_libwasmvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
TESTING_CACHE_SIZE = 100 // MiB
)

var TESTING_CAPABILITIES = []string{"staking", "stargate", "iterator"}
var TESTING_CAPABILITIES = []string{"staking", "stargate", "iterator", "cosmwasm_1_1", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "cosmwasm_2_0", "cosmwasm_2_1", "cosmwasm_2_2"}

const (
CYBERPUNK_TEST_CONTRACT = "./testdata/cyberpunk.wasm"
Expand Down
65 changes: 29 additions & 36 deletions libwasmvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions libwasmvm/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,10 @@ mod tests {
assert!(!hackatom_report.has_ibc_entry_points);
assert_eq!(
hackatom_report.required_capabilities.consume().unwrap(),
b""
b"cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0,cosmwasm_2_1,cosmwasm_2_2"
);
assert!(hackatom_report.contract_migrate_version.is_some);
assert_eq!(hackatom_report.contract_migrate_version.value, 42);
assert_eq!(hackatom_report.contract_migrate_version.value, 420);

let mut error_msg: UnmanagedVector = UnmanagedVector::default();
let ibc_reflect_report = analyze_code(
Expand All @@ -813,7 +813,10 @@ mod tests {
let required_capabilities =
String::from_utf8_lossy(&ibc_reflect_report.required_capabilities.consume().unwrap())
.to_string();
assert_eq!(required_capabilities, "iterator,stargate");
assert_eq!(
required_capabilities,
"cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0,cosmwasm_2_1,cosmwasm_2_2,iterator,stargate"
);

release_cache(cache_ptr);
}
Expand Down
2 changes: 1 addition & 1 deletion libwasmvm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn handle_cpu_loop_with_cache() {
let backend = mock_backend(&[]);
let options = CacheOptions::new(
TempDir::new().unwrap().path().to_path_buf(),
capabilities_from_csv("staking"),
capabilities_from_csv("cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0,cosmwasm_2_1,cosmwasm_2_2,staking,iterator,stargate"),
MEMORY_CACHE_SIZE,
MEMORY_LIMIT,
);
Expand Down
Loading