Skip to content

Commit 1ab59a4

Browse files
committed
Test the default_gas_limit works properly
1 parent 41678f4 commit 1ab59a4

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

contracts/cw20-ics20/src/contract.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,9 @@ mod test {
528528
}
529529

530530
#[test]
531-
fn execute_cw20_fails_if_not_whitelisted() {
531+
fn execute_cw20_fails_if_not_whitelisted_unless_default_gas_limit() {
532532
let send_channel = "channel-15";
533-
let mut deps = setup(&["channel-3", send_channel], &[]);
533+
let mut deps = setup(&[send_channel], &[]);
534534

535535
let cw20_addr = "my-token";
536536
let transfer = TransferMsg {
@@ -544,10 +544,23 @@ mod test {
544544
msg: to_binary(&transfer).unwrap(),
545545
});
546546

547-
// works with proper funds
547+
// rejected as not on allow list
548548
let info = mock_info(cw20_addr, &[]);
549-
let err = execute(deps.as_mut(), mock_env(), info, msg).unwrap_err();
549+
let err = execute(deps.as_mut(), mock_env(), info.clone(), msg.clone()).unwrap_err();
550550
assert_eq!(err, ContractError::NotOnAllowList);
551+
552+
// add a default gas limit
553+
migrate(
554+
deps.as_mut(),
555+
mock_env(),
556+
MigrateMsg {
557+
default_gas_limit: Some(123456),
558+
},
559+
)
560+
.unwrap();
561+
562+
// try again
563+
execute(deps.as_mut(), mock_env(), info, msg).unwrap();
551564
}
552565

553566
#[test]

contracts/cw20-ics20/src/ibc.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ mod test {
390390
use super::*;
391391
use crate::test_helpers::*;
392392

393-
use crate::contract::{execute, query_channel};
394-
use crate::msg::{ExecuteMsg, TransferMsg};
393+
use crate::contract::{execute, migrate, query_channel};
394+
use crate::msg::{ExecuteMsg, MigrateMsg, TransferMsg};
395395
use cosmwasm_std::testing::{mock_env, mock_info};
396396
use cosmwasm_std::{coins, to_vec, IbcEndpoint, IbcMsg, IbcTimeout, Timestamp};
397397
use cw20::Cw20ReceiveMsg;
@@ -625,4 +625,39 @@ mod test {
625625
assert_eq!(state.balances, vec![Amount::native(111111111, denom)]);
626626
assert_eq!(state.total_sent, vec![Amount::native(987654321, denom)]);
627627
}
628+
629+
#[test]
630+
fn check_gas_limit_handles_all_cases() {
631+
let send_channel = "channel-9";
632+
let allowed = "foobar";
633+
let allowed_gas = 777666;
634+
let mut deps = setup(&[send_channel], &[(allowed, allowed_gas)]);
635+
636+
// allow list will get proper gas
637+
let limit = check_gas_limit(deps.as_ref(), &Amount::cw20(500, allowed)).unwrap();
638+
assert_eq!(limit, Some(allowed_gas));
639+
640+
// non-allow list will error
641+
let random = "tokenz";
642+
check_gas_limit(deps.as_ref(), &Amount::cw20(500, random)).unwrap_err();
643+
644+
// add default_gas_limit
645+
let def_limit = 54321;
646+
migrate(
647+
deps.as_mut(),
648+
mock_env(),
649+
MigrateMsg {
650+
default_gas_limit: Some(def_limit),
651+
},
652+
)
653+
.unwrap();
654+
655+
// allow list still gets proper gas
656+
let limit = check_gas_limit(deps.as_ref(), &Amount::cw20(500, allowed)).unwrap();
657+
assert_eq!(limit, Some(allowed_gas));
658+
659+
// non-allow list will now get default
660+
let limit = check_gas_limit(deps.as_ref(), &Amount::cw20(500, random)).unwrap();
661+
assert_eq!(limit, Some(def_limit));
662+
}
628663
}

0 commit comments

Comments
 (0)