Skip to content

Commit

Permalink
changed returned value from contract
Browse files Browse the repository at this point in the history
  • Loading branch information
eshelB committed Sep 19, 2023
1 parent e6bdfdb commit 0638407
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,11 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> S
send_multiple_sub_messages_with_reply_with_panic(env, deps)
}
ExecuteMsg::IncrementAndSendFailingSubmessage { reply_on } => {
increment(env.clone(), deps, 1)?;
send_failing_submsg(env, reply_on)
increment_simple(deps)?;
let mut response = send_failing_submsg(env, reply_on)?;
response.data = Some((count as u32).to_be_bytes().into());

Ok(response)
},
ExecuteMsg::InitV10 {
counter,
Expand Down Expand Up @@ -1441,6 +1444,13 @@ pub fn increment(env: Env, deps: DepsMut, c: u64) -> StdResult<Response> {
Ok(resp)
}

pub fn increment_simple(deps: DepsMut) -> StdResult<u64> {
let new_count = count_read(deps.storage).load()? + 1;
count(deps.storage).save(&new_count)?;

Ok(new_count)
}

pub fn transfer_money(_deps: DepsMut, amount: u64) -> StdResult<Response> {
let mut resp = Response::default();
resp.messages.push(SubMsg {
Expand Down Expand Up @@ -2280,7 +2290,9 @@ pub fn reply(deps: DepsMut, env: Env, reply: Reply) -> StdResult<Response> {
.add_attribute_plaintext("attr_reply", "🦄")
.set_data(to_binary("reply")?)),
//(9000, SubMsgResult::Err(_)) => Err(StdError::generic_err("err")),
(9200, SubMsgResult::Err(_)) => Ok(Response::default().set_data("err".as_bytes())),
(9200, SubMsgResult::Err(_)) => Ok(Response::default().set_data(
(count_read(deps.storage).load()? as u32).to_be_bytes()
)),
(11337, SubMsgResult::Ok(SubMsgResponse { data, .. })) => {


Expand Down
10 changes: 1 addition & 9 deletions x/compute/internal/keeper/secret_contracts_submsgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper
import (
"encoding/binary"
"encoding/json"
"fmt"
"math"
"testing"

Expand Down Expand Up @@ -46,24 +45,17 @@ func TestV1MultipleSubmessagesNoReply(t *testing.T) {
func TestV1StatePersistsAfterSubmessageFails(t *testing.T) {
ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, TestContractPaths[v1Contract], sdk.NewCoins())

fmt.Println("ESHELDEBUG: before init") // todo remove
_, _, contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, nil, privKeyA, `{"counter":{"counter":10, "expires":100}}`, true, true, defaultGasForTests)
fmt.Println("ESHELDEBUG: after init") // todo remove
_, _, data, _, _, err := execHelper(t, keeper, ctx, contractAddress, walletA, privKeyA, `{"increment_and_send_failing_submessage":{"reply_on":"always"}}`, true, true, math.MaxUint64, 0)
fmt.Println("ESHELDEBUG: after exec") // todo remove

require.Empty(t, err)
fmt.Println("ESHELDEBUG: after empty") // todo remove
require.Equal(t, uint32(10), binary.BigEndian.Uint32(data))
fmt.Println("ESHELDEBUG: after require") // todo remove
require.Equal(t, uint32(11), binary.BigEndian.Uint32(data))

queryRes, qErr := queryHelper(t, keeper, ctx, contractAddress, `{"get":{}}`, true, true, math.MaxUint64)
fmt.Println("ESHELDEBUG: after query") // todo remove
require.Empty(t, qErr)

var resp v1QueryResponse
e := json.Unmarshal([]byte(queryRes), &resp)
fmt.Println("ESHELDEBUG: after unmarshal") // todo remove
require.NoError(t, e)
require.Equal(t, uint32(11), resp.Get.Count)
}
Expand Down

0 comments on commit 0638407

Please sign in to comment.