Skip to content

Commit

Permalink
Annotate init_contract_state and handle Option
Browse files Browse the repository at this point in the history
  • Loading branch information
bugarela committed Jun 14, 2024
1 parent 2e6c4a5 commit 0ee9e21
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/boilerplate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ pub fn init_value_for_type(ctx: &Context, ty: String) -> String {
return "[]".to_string();
}

if ty.starts_with("Option") {
return "None".to_string();
}

let typ = ty.split('[').next().unwrap();
if ctx.structs.contains_key(typ) {
// Type is a struct, initialize fields recursively
Expand Down Expand Up @@ -196,7 +200,7 @@ pub fn post_items(ctx: &Context) -> String {
{contract_state}
}}
pure val init_contract_state = {{
pure val init_contract_state: ContractState = {{
{initializer}
}}
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/integration_tests__ctf01.snap
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module oaksecurity_cosmwasm_ctf_01 {
lockups: int -> Lockup
}

pure val init_contract_state = {
pure val init_contract_state: ContractState = {
last_id: 0,
lockups: Map()
}
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/integration_tests__ctf02.snap
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module oaksecurity_cosmwasm_ctf_02 {
voting_power: Addr -> UserInfo
}

pure val init_contract_state = {
pure val init_contract_state: ContractState = {
voting_power: Map()
}

Expand Down
6 changes: 3 additions & 3 deletions tests/snapshots/integration_tests__ctf03.snap
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ module flash_loan {
flash_loan: FlashLoanState
}

pure val init_contract_state = {
pure val init_contract_state: ContractState = {
config: "<missing-value>",
flash_loan: "<missing-value>"
}
Expand Down Expand Up @@ -254,7 +254,7 @@ module mock_arb {
config: Config
}

pure val init_contract_state = {
pure val init_contract_state: ContractState = {
config: "<missing-value>"
}

Expand Down Expand Up @@ -389,7 +389,7 @@ module proxy {
config: Config
}

pure val init_contract_state = {
pure val init_contract_state: ContractState = {
config: "<missing-value>"
}

Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/integration_tests__ctf04.snap
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module oaksecurity_cosmwasm_ctf_04 {
balances: Addr -> Balance
}

pure val init_contract_state = {
pure val init_contract_state: ContractState = {
config: { total_supply: 0 },
balances: Map()
}
Expand Down
4 changes: 2 additions & 2 deletions tests/snapshots/integration_tests__ctf05.snap
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ module oaksecurity_cosmwasm_ctf_05 {
balances: Addr -> int
}

pure val init_contract_state = {
state: { current_owner: "s1", proposed_owner: "<missing-value>" },
pure val init_contract_state: ContractState = {
state: { current_owner: "s1", proposed_owner: None },
balances: Map()
}

Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/integration_tests__ctf06.snap
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module oaksecurity_cosmwasm_ctf_06 {
proposal: Proposal
}

pure val init_contract_state = {
pure val init_contract_state: ContractState = {
config: { voting_window: 0, voting_token: "s1", owner: "s1" },
proposal: { proposer: "s1", timestamp: 0 }
}
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/integration_tests__ctf07.snap
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module oaksecurity_cosmwasm_ctf_07 {
balances: Addr -> int
}

pure val init_contract_state = {
pure val init_contract_state: ContractState = {
top_depositor: "s1",
owner: "s1",
threshold: 0,
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/integration_tests__ctf08.snap
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ module oaksecurity_cosmwasm_ctf_08 {
operations: Operations
}

pure val init_contract_state = {
pure val init_contract_state: ContractState = {
config: { nft_contract: "s1" },
sales: Map(),
trades: Map(),
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/integration_tests__ctf09.snap
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module oaksecurity_cosmwasm_ctf_09 {
users: Addr -> UserRewardInfo
}

pure val init_contract_state = {
pure val init_contract_state: ContractState = {
state: { owner: "s1", total_staked: 0, global_index: 0 },
users: Map()
}
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/integration_tests__ctf10.snap
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module oaksecurity_cosmwasm_ctf_10 {
whitelist: Whitelist
}

pure val init_contract_state = {
pure val init_contract_state: ContractState = {
config: { nft_contract: "s1", mint_per_user: 0, total_tokens: 0 },
whitelist: { users: [] }
}
Expand Down

0 comments on commit 0ee9e21

Please sign in to comment.