JoshOrndorff / substrate-recipes

A Hands-On Cookbook for Aspiring Blockchain Chefs
GNU General Public License v3.0
380 stars 184 forks source link

How can i write test case for function fetch_github_info in Offchain worker example #459

Open CocDap opened 3 years ago

CocDap commented 3 years ago

Hello, I try to write a test case for checking function fetch_github_info in offchain worker. But it failed.

#[test]                                                                                                              
fn fetch_submit_info_works() {                                                                                       
      let (mut t, _, _) = ExternalityBuilder::build();                                                                 
      t.execute_with(|| {                                                                                              
            System::set_block_number(4);
            assert_ok!(OcwDemo::fetch_github_info())
});
}

It catch Error in line 405 that Response doesnt response from API in functionfn fetch_from_remote() image image

But when I check in Polkadot.js.org it works and has fetched data from API Can you have any idea to fix this? I updated, but it failed because data stores in offchain worker has None image

Thank you very much