github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/wasm/client/proposal_handler_test.go (about) 1 package client 2 3 //import ( 4 // "bytes" 5 // "encoding/json" 6 // "fmt" 7 // "net/http" 8 // "net/http/httptest" 9 // "os" 10 // "testing" 11 // 12 // "github.com/gorilla/mux" 13 // "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client" 14 // "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/flags" 15 // authtypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth/types" 16 // "github.com/stretchr/testify/require" 17 // 18 // "github.com/fibonacci-chain/fbc/x/wasm/keeper" 19 //) 20 // 21 //func TestGovRestHandlers(t *testing.T) { 22 // type dict map[string]interface{} 23 // var ( 24 // anyAddress = "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz" 25 // aBaseReq = dict{ 26 // "from": anyAddress, 27 // "memo": "rest test", 28 // "chain_id": "testing", 29 // "account_number": "1", 30 // "sequence": "1", 31 // "fees": []dict{{"denom": "ustake", "amount": "1000000"}}, 32 // } 33 // ) 34 // encodingConfig := keeper.MakeEncodingConfig(t) 35 // clientCtx := client.Context{}. 36 // WithCodec(encodingConfig.Marshaler). 37 // WithTxConfig(encodingConfig.TxConfig). 38 // WithLegacyAmino(encodingConfig.Amino). 39 // WithInput(os.Stdin). 40 // WithAccountRetriever(authtypes.AccountRetriever{}). 41 // WithBroadcastMode(flags.BroadcastBlock). 42 // WithChainID("testing") 43 // 44 // // router setup as in gov/client/rest/tx.go 45 // propSubRtr := mux.NewRouter().PathPrefix("/gov/proposals").Subrouter() 46 // for _, ph := range ProposalHandlers { 47 // r := ph.RESTHandler(clientCtx) 48 // propSubRtr.HandleFunc(fmt.Sprintf("/%s", r.SubRoute), r.Handler).Methods("POST") 49 // } 50 // 51 // specs := map[string]struct { 52 // srcBody dict 53 // srcPath string 54 // expCode int 55 // }{ 56 // "store-code": { 57 // srcPath: "/gov/proposals/wasm_store_code", 58 // srcBody: dict{ 59 // "title": "Test Proposal", 60 // "description": "My proposal", 61 // "type": "store-code", 62 // "run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz", 63 // "wasm_byte_code": []byte("valid wasm byte code"), 64 // "source": "https://example.com/", 65 // "builder": "my/builder:tag", 66 // "instantiate_permission": dict{ 67 // "permission": "OnlyAddress", 68 // "address": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 69 // }, 70 // "deposit": []dict{{"denom": "ustake", "amount": "10"}}, 71 // "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 72 // "base_req": aBaseReq, 73 // }, 74 // expCode: http.StatusOK, 75 // }, 76 // "store-code without permission": { 77 // srcPath: "/gov/proposals/wasm_store_code", 78 // srcBody: dict{ 79 // "title": "Test Proposal", 80 // "description": "My proposal", 81 // "type": "store-code", 82 // "run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz", 83 // "wasm_byte_code": []byte("valid wasm byte code"), 84 // "source": "https://example.com/", 85 // "builder": "my/builder:tag", 86 // "deposit": []dict{{"denom": "ustake", "amount": "10"}}, 87 // "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 88 // "base_req": aBaseReq, 89 // }, 90 // expCode: http.StatusOK, 91 // }, 92 // "store-code invalid permission": { 93 // srcPath: "/gov/proposals/wasm_store_code", 94 // srcBody: dict{ 95 // "title": "Test Proposal", 96 // "description": "My proposal", 97 // "type": "store-code", 98 // "run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz", 99 // "wasm_byte_code": []byte("valid wasm byte code"), 100 // "source": "https://example.com/", 101 // "builder": "my/builder:tag", 102 // "instantiate_permission": dict{ 103 // "permission": "Nobody", 104 // "address": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 105 // }, 106 // "deposit": []dict{{"denom": "ustake", "amount": "10"}}, 107 // "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 108 // "base_req": aBaseReq, 109 // }, 110 // expCode: http.StatusBadRequest, 111 // }, 112 // "store-code with incomplete proposal data: blank title": { 113 // srcPath: "/gov/proposals/wasm_store_code", 114 // srcBody: dict{ 115 // "title": "", 116 // "description": "My proposal", 117 // "type": "store-code", 118 // "run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz", 119 // "wasm_byte_code": []byte("valid wasm byte code"), 120 // "source": "https://example.com/", 121 // "builder": "my/builder:tag", 122 // "instantiate_permission": dict{ 123 // "permission": "OnlyAddress", 124 // "address": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 125 // }, 126 // "deposit": []dict{{"denom": "ustake", "amount": "10"}}, 127 // "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 128 // "base_req": aBaseReq, 129 // }, 130 // expCode: http.StatusBadRequest, 131 // }, 132 // "store-code with incomplete content data: no wasm_byte_code": { 133 // srcPath: "/gov/proposals/wasm_store_code", 134 // srcBody: dict{ 135 // "title": "Test Proposal", 136 // "description": "My proposal", 137 // "type": "store-code", 138 // "run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz", 139 // "wasm_byte_code": "", 140 // "source": "https://example.com/", 141 // "builder": "my/builder:tag", 142 // "instantiate_permission": dict{ 143 // "permission": "OnlyAddress", 144 // "address": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 145 // }, 146 // "deposit": []dict{{"denom": "ustake", "amount": "10"}}, 147 // "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 148 // "base_req": aBaseReq, 149 // }, 150 // expCode: http.StatusBadRequest, 151 // }, 152 // "instantiate contract": { 153 // srcPath: "/gov/proposals/wasm_instantiate", 154 // srcBody: dict{ 155 // "title": "Test Proposal", 156 // "description": "My proposal", 157 // "type": "instantiate", 158 // "run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz", 159 // "admin": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz", 160 // "code_id": "1", 161 // "label": "https://example.com/", 162 // "msg": dict{"recipient": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz"}, 163 // "funds": []dict{{"denom": "ustake", "amount": "100"}}, 164 // "deposit": []dict{{"denom": "ustake", "amount": "10"}}, 165 // "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 166 // "base_req": aBaseReq, 167 // }, 168 // expCode: http.StatusOK, 169 // }, 170 // "migrate contract": { 171 // srcPath: "/gov/proposals/wasm_migrate", 172 // srcBody: dict{ 173 // "title": "Test Proposal", 174 // "description": "My proposal", 175 // "type": "migrate", 176 // "contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", 177 // "code_id": "1", 178 // "msg": dict{"foo": "bar"}, 179 // "run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz", 180 // "deposit": []dict{{"denom": "ustake", "amount": "10"}}, 181 // "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 182 // "base_req": aBaseReq, 183 // }, 184 // expCode: http.StatusOK, 185 // }, 186 // "execute contract": { 187 // srcPath: "/gov/proposals/wasm_execute", 188 // srcBody: dict{ 189 // "title": "Test Proposal", 190 // "description": "My proposal", 191 // "type": "migrate", 192 // "contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", 193 // "msg": dict{"foo": "bar"}, 194 // "run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz", 195 // "deposit": []dict{{"denom": "ustake", "amount": "10"}}, 196 // "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 197 // "base_req": aBaseReq, 198 // }, 199 // expCode: http.StatusOK, 200 // }, 201 // "execute contract fails with no run_as": { 202 // srcPath: "/gov/proposals/wasm_execute", 203 // srcBody: dict{ 204 // "title": "Test Proposal", 205 // "description": "My proposal", 206 // "type": "migrate", 207 // "contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", 208 // "msg": dict{"foo": "bar"}, 209 // "deposit": []dict{{"denom": "ustake", "amount": "10"}}, 210 // "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 211 // "base_req": aBaseReq, 212 // }, 213 // expCode: http.StatusBadRequest, 214 // }, 215 // "execute contract fails with no message": { 216 // srcPath: "/gov/proposals/wasm_execute", 217 // srcBody: dict{ 218 // "title": "Test Proposal", 219 // "description": "My proposal", 220 // "type": "migrate", 221 // "contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", 222 // "run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz", 223 // "deposit": []dict{{"denom": "ustake", "amount": "10"}}, 224 // "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 225 // "base_req": aBaseReq, 226 // }, 227 // expCode: http.StatusBadRequest, 228 // }, 229 // "sudo contract": { 230 // srcPath: "/gov/proposals/wasm_sudo", 231 // srcBody: dict{ 232 // "title": "Test Proposal", 233 // "description": "My proposal", 234 // "type": "migrate", 235 // "contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", 236 // "msg": dict{"foo": "bar"}, 237 // "deposit": []dict{{"denom": "ustake", "amount": "10"}}, 238 // "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 239 // "base_req": aBaseReq, 240 // }, 241 // expCode: http.StatusOK, 242 // }, 243 // "sudo contract fails with no message": { 244 // srcPath: "/gov/proposals/wasm_sudo", 245 // srcBody: dict{ 246 // "title": "Test Proposal", 247 // "description": "My proposal", 248 // "type": "migrate", 249 // "contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", 250 // "deposit": []dict{{"denom": "ustake", "amount": "10"}}, 251 // "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 252 // "base_req": aBaseReq, 253 // }, 254 // expCode: http.StatusBadRequest, 255 // }, 256 // "update contract admin": { 257 // srcPath: "/gov/proposals/wasm_update_admin", 258 // srcBody: dict{ 259 // "title": "Test Proposal", 260 // "description": "My proposal", 261 // "type": "migrate", 262 // "contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", 263 // "new_admin": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz", 264 // "deposit": []dict{{"denom": "ustake", "amount": "10"}}, 265 // "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 266 // "base_req": aBaseReq, 267 // }, 268 // expCode: http.StatusOK, 269 // }, 270 // "clear contract admin": { 271 // srcPath: "/gov/proposals/wasm_clear_admin", 272 // srcBody: dict{ 273 // "title": "Test Proposal", 274 // "description": "My proposal", 275 // "type": "migrate", 276 // "contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", 277 // "deposit": []dict{{"denom": "ustake", "amount": "10"}}, 278 // "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", 279 // "base_req": aBaseReq, 280 // }, 281 // expCode: http.StatusOK, 282 // }, 283 // } 284 // for msg, spec := range specs { 285 // t.Run(msg, func(t *testing.T) { 286 // src, err := json.Marshal(spec.srcBody) 287 // require.NoError(t, err) 288 // 289 // // when 290 // r := httptest.NewRequest("POST", spec.srcPath, bytes.NewReader(src)) 291 // w := httptest.NewRecorder() 292 // propSubRtr.ServeHTTP(w, r) 293 // 294 // // then 295 // require.Equal(t, spec.expCode, w.Code, w.Body.String()) 296 // }) 297 // } 298 //}