Skip to content
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

feat: modify call_something functions to tell EventManager's info to x/wasm #88

Merged
merged 10 commits into from
Feb 17, 2023
13 changes: 12 additions & 1 deletion api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,23 @@ func TestValidateAddressFailure(t *testing.T) {

// make sure the call doesn't error, but we get a JSON-encoded error result from ContractResult
igasMeter := GasMeter(gasMeter)
res, _, err := Instantiate(cache, checksum, env, info, msg, &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
res, eventsData, attributesData, _, err := Instantiate(cache, checksum, env, info, msg, &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
require.NoError(t, err)
var result types.ContractResult
err = json.Unmarshal(res, &result)
require.NoError(t, err)

// make sure it does not uses EventManager
var events types.Events
err = events.UnmarshalJSON(eventsData)
require.NoError(t, err)
require.Equal(t, 0, len(events))

var attributes types.EventAttributes
err = attributes.UnmarshalJSON(attributesData)
require.NoError(t, err)
require.Equal(t, 0, len(attributes))

// ensure the error message is what we expect
require.Nil(t, result.Ok)
// with this error
Expand Down
20 changes: 20 additions & 0 deletions api/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ struct UnmanagedVector instantiate(struct cache_t *cache,
uint64_t gas_limit,
bool print_debug,
uint64_t *gas_used,
struct UnmanagedVector *events,
struct UnmanagedVector *attributes,
struct UnmanagedVector *error_msg);

struct UnmanagedVector execute(struct cache_t *cache,
Expand All @@ -362,6 +364,8 @@ struct UnmanagedVector execute(struct cache_t *cache,
uint64_t gas_limit,
bool print_debug,
uint64_t *gas_used,
struct UnmanagedVector *events,
struct UnmanagedVector *attributes,
struct UnmanagedVector *error_msg);

struct UnmanagedVector migrate(struct cache_t *cache,
Expand All @@ -374,6 +378,8 @@ struct UnmanagedVector migrate(struct cache_t *cache,
uint64_t gas_limit,
bool print_debug,
uint64_t *gas_used,
struct UnmanagedVector *events,
struct UnmanagedVector *attributes,
struct UnmanagedVector *error_msg);

struct UnmanagedVector sudo(struct cache_t *cache,
Expand All @@ -386,6 +392,8 @@ struct UnmanagedVector sudo(struct cache_t *cache,
uint64_t gas_limit,
bool print_debug,
uint64_t *gas_used,
struct UnmanagedVector *events,
struct UnmanagedVector *attributes,
struct UnmanagedVector *error_msg);

struct UnmanagedVector reply(struct cache_t *cache,
Expand All @@ -398,6 +406,8 @@ struct UnmanagedVector reply(struct cache_t *cache,
uint64_t gas_limit,
bool print_debug,
uint64_t *gas_used,
struct UnmanagedVector *events,
struct UnmanagedVector *attributes,
struct UnmanagedVector *error_msg);

struct UnmanagedVector query(struct cache_t *cache,
Expand Down Expand Up @@ -434,6 +444,8 @@ struct UnmanagedVector ibc_channel_connect(struct cache_t *cache,
uint64_t gas_limit,
bool print_debug,
uint64_t *gas_used,
struct UnmanagedVector *events,
struct UnmanagedVector *attributes,
struct UnmanagedVector *error_msg);

struct UnmanagedVector ibc_channel_close(struct cache_t *cache,
Expand All @@ -446,6 +458,8 @@ struct UnmanagedVector ibc_channel_close(struct cache_t *cache,
uint64_t gas_limit,
bool print_debug,
uint64_t *gas_used,
struct UnmanagedVector *events,
struct UnmanagedVector *attributes,
struct UnmanagedVector *error_msg);

struct UnmanagedVector ibc_packet_receive(struct cache_t *cache,
Expand All @@ -458,6 +472,8 @@ struct UnmanagedVector ibc_packet_receive(struct cache_t *cache,
uint64_t gas_limit,
bool print_debug,
uint64_t *gas_used,
struct UnmanagedVector *events,
struct UnmanagedVector *attributes,
struct UnmanagedVector *error_msg);

struct UnmanagedVector ibc_packet_ack(struct cache_t *cache,
Expand All @@ -470,6 +486,8 @@ struct UnmanagedVector ibc_packet_ack(struct cache_t *cache,
uint64_t gas_limit,
bool print_debug,
uint64_t *gas_used,
struct UnmanagedVector *events,
struct UnmanagedVector *attributes,
struct UnmanagedVector *error_msg);

struct UnmanagedVector ibc_packet_timeout(struct cache_t *cache,
Expand All @@ -482,6 +500,8 @@ struct UnmanagedVector ibc_packet_timeout(struct cache_t *cache,
uint64_t gas_limit,
bool print_debug,
uint64_t *gas_used,
struct UnmanagedVector *events,
struct UnmanagedVector *attributes,
struct UnmanagedVector *error_msg);

struct UnmanagedVector new_unmanaged_vector(bool nil, const uint8_t *ptr, uintptr_t length);
Expand Down
24 changes: 22 additions & 2 deletions api/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,37 @@ func setupQueueContractWithData(t *testing.T, cache Cache, values ...int) queueD
msg := []byte(`{}`)

igasMeter1 := GasMeter(gasMeter1)
res, _, err := Instantiate(cache, checksum, env, info, msg, &igasMeter1, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
res, eventsData, attributesData, _, err := Instantiate(cache, checksum, env, info, msg, &igasMeter1, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
require.NoError(t, err)
requireOkResponse(t, res, 0)

// make sure it does not uses EventManager
var eventsByEventManager types.Events
err = eventsByEventManager.UnmarshalJSON(eventsData)
require.NoError(t, err)
require.Equal(t, 0, len(eventsByEventManager))

var attributesByEventManager types.EventAttributes
err = attributesByEventManager.UnmarshalJSON(attributesData)
require.NoError(t, err)
require.Equal(t, 0, len(attributesByEventManager))

for _, value := range values {
// push 17
var gasMeter2 GasMeter = NewMockGasMeter(TESTING_GAS_LIMIT)
push := []byte(fmt.Sprintf(`{"enqueue":{"value":%d}}`, value))
res, _, err = Execute(cache, checksum, env, info, push, &gasMeter2, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
res, eventsData, attributesData, _, err = Execute(cache, checksum, env, info, push, &gasMeter2, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
require.NoError(t, err)
requireOkResponse(t, res, 0)

// make sure it does not uses EventManager
err = eventsByEventManager.UnmarshalJSON(eventsData)
require.NoError(t, err)
require.Equal(t, 0, len(eventsByEventManager))

err = attributesByEventManager.UnmarshalJSON(attributesData)
require.NoError(t, err)
require.Equal(t, 0, len(attributesByEventManager))
}

return queueData{
Expand Down
Loading