Skip to content

Commit

Permalink
🐛 add missing check owner step in setters
Browse files Browse the repository at this point in the history
  • Loading branch information
bal7hazar committed Sep 1, 2022
1 parent 67d8113 commit c7d7f43
Show file tree
Hide file tree
Showing 18 changed files with 419 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/project/library.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ namespace CarbonableProject:
}(external_url_len : felt, external_url : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(external_url_len, external_url)
StringCodec.write('external_url', str)
return ()
Expand All @@ -236,6 +237,7 @@ namespace CarbonableProject:
}(description_len : felt, description : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(description_len, description)
StringCodec.write('description', str)
return ()
Expand All @@ -249,6 +251,7 @@ namespace CarbonableProject:
}(holder_len : felt, holder : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(holder_len, holder)
StringCodec.write('holder', str)
return ()
Expand All @@ -262,6 +265,7 @@ namespace CarbonableProject:
}(certifier_len : felt, certifier : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(certifier_len, certifier)
StringCodec.write('certifier', str)
return ()
Expand All @@ -275,6 +279,7 @@ namespace CarbonableProject:
}(land_len : felt, land : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(land_len, land)
StringCodec.write('land', str)
return ()
Expand All @@ -288,6 +293,7 @@ namespace CarbonableProject:
}(unit_land_surface_len : felt, unit_land_surface : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(unit_land_surface_len, unit_land_surface)
StringCodec.write('unit_land_surface', str)
return ()
Expand All @@ -301,6 +307,7 @@ namespace CarbonableProject:
}(country_len : felt, country : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(country_len, country)
StringCodec.write('country', str)
return ()
Expand All @@ -314,6 +321,7 @@ namespace CarbonableProject:
}(expiration_len : felt, expiration : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(expiration_len, expiration)
StringCodec.write('expiration', str)
return ()
Expand All @@ -327,6 +335,7 @@ namespace CarbonableProject:
}(total_co2_sequestration_len : felt, total_co2_sequestration : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(total_co2_sequestration_len, total_co2_sequestration)
StringCodec.write('total_co2_sequestration', str)
return ()
Expand All @@ -340,6 +349,7 @@ namespace CarbonableProject:
}(unit_co2_sequestration_len : felt, unit_co2_sequestration : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(unit_co2_sequestration_len, unit_co2_sequestration)
StringCodec.write('unit_co2_sequestration', str)
return ()
Expand All @@ -353,6 +363,7 @@ namespace CarbonableProject:
}(sequestration_color_len : felt, sequestration_color : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(sequestration_color_len, sequestration_color)
StringCodec.write('sequestration_color', str)
return ()
Expand All @@ -366,6 +377,7 @@ namespace CarbonableProject:
}(sequestration_type_len : felt, sequestration_type : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(sequestration_type_len, sequestration_type)
StringCodec.write('sequestration_type', str)
return ()
Expand All @@ -379,6 +391,7 @@ namespace CarbonableProject:
}(sequestration_category_len : felt, sequestration_category : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(sequestration_category_len, sequestration_category)
StringCodec.write('sequestration_category', str)
return ()
Expand All @@ -392,6 +405,7 @@ namespace CarbonableProject:
}(background_color_len : felt, background_color : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(background_color_len, background_color)
StringCodec.write('background_color', str)
return ()
Expand All @@ -405,6 +419,7 @@ namespace CarbonableProject:
}(animation_url_len : felt, animation_url : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(animation_url_len, animation_url)
StringCodec.write('animation_url', str)
return ()
Expand All @@ -418,6 +433,7 @@ namespace CarbonableProject:
}(youtube_url_len : felt, youtube_url : felt*):
alloc_locals

Ownable.assert_only_owner()
let (str) = StringCodec.ss_arr_to_string(youtube_url_len, youtube_url)
StringCodec.write('youtube_url', str)
return ()
Expand Down
23 changes: 23 additions & 0 deletions tests/units/project/test_animation_url.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@ func test_animation_url{

return ()
end

@external
func test_animation_url_revert_not_owner{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr
}():
alloc_locals

# prepare project instance
let (local context) = prepare()

# run scenario
%{ stop=start_prank(context.signers.anyone) %}

let ss = 'https://animation.com'
let (str) = StringCodec.ss_to_string(ss)

%{ expect_revert("TRANSACTION_FAILED", "Ownable: caller is not the owner") %}
CarbonableProject.set_animation_url(animation_url_len=str.len, animation_url=str.data)

%{ stop() %}

return ()
end
23 changes: 23 additions & 0 deletions tests/units/project/test_background_color.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@ func test_background_color{

return ()
end

@external
func test_background_color_revert_not_owner{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr
}():
alloc_locals

# prepare project instance
let (local context) = prepare()

# run scenario
%{ stop=start_prank(context.signers.anyone) %}

let ss = 'green'
let (str) = StringCodec.ss_to_string(ss)

%{ expect_revert("TRANSACTION_FAILED", "Ownable: caller is not the owner") %}
CarbonableProject.set_background_color(background_color_len=str.len, background_color=str.data)

%{ stop() %}

return ()
end
23 changes: 23 additions & 0 deletions tests/units/project/test_certifier.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@ func test_certifier{

return ()
end

@external
func test_certifier_revert_not_owner{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr
}():
alloc_locals

# prepare project instance
let (local context) = prepare()

# run scenario
%{ stop=start_prank(context.signers.anyone) %}

let ss = 'Certifier'
let (str) = StringCodec.ss_to_string(ss)

%{ expect_revert("TRANSACTION_FAILED", "Ownable: caller is not the owner") %}
CarbonableProject.set_certifier(certifier_len=str.len, certifier=str.data)

%{ stop() %}

return ()
end
23 changes: 23 additions & 0 deletions tests/units/project/test_country.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@ func test_country{

return ()
end

@external
func test_country_revert_not_owner{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr
}():
alloc_locals

# prepare project instance
let (local context) = prepare()

# run scenario
%{ stop=start_prank(context.signers.anyone) %}

let ss = 'Country'
let (str) = StringCodec.ss_to_string(ss)

%{ expect_revert("TRANSACTION_FAILED", "Ownable: caller is not the owner") %}
CarbonableProject.set_country(country_len=str.len, country=str.data)

%{ stop() %}

return ()
end
23 changes: 23 additions & 0 deletions tests/units/project/test_description.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@ func test_description{

return ()
end

@external
func test_description_revert_not_owner{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr
}():
alloc_locals

# prepare project instance
let (local context) = prepare()

# run scenario
%{ stop=start_prank(context.signers.anyone) %}

let ss = 'This is a description'
let (str) = StringCodec.ss_to_string(ss)

%{ expect_revert("TRANSACTION_FAILED", "Ownable: caller is not the owner") %}
CarbonableProject.set_description(description_len=str.len, description=str.data)

%{ stop() %}

return ()
end
23 changes: 23 additions & 0 deletions tests/units/project/test_expiration.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@ func test_expiration{

return ()
end

@external
func test_expiration_revert_not_owner{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr
}():
alloc_locals

# prepare project instance
let (local context) = prepare()

# run scenario
%{ stop=start_prank(context.signers.anyone) %}

let ss = '2042'
let (str) = StringCodec.ss_to_string(ss)

%{ expect_revert("TRANSACTION_FAILED", "Ownable: caller is not the owner") %}
CarbonableProject.set_expiration(expiration_len=str.len, expiration=str.data)

%{ stop() %}

return ()
end
23 changes: 23 additions & 0 deletions tests/units/project/test_external_url .cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@ func test_external_url{

return ()
end

@external
func test_external_url_revert_not_owner{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr
}():
alloc_locals

# prepare project instance
let (local context) = prepare()

# run scenario
%{ stop=start_prank(context.signers.anyone) %}

let ss = 'https://external.com'
let (str) = StringCodec.ss_to_string(ss)

%{ expect_revert("TRANSACTION_FAILED", "Ownable: caller is not the owner") %}
CarbonableProject.set_external_url(external_url_len=str.len, external_url=str.data)

%{ stop() %}

return ()
end
23 changes: 23 additions & 0 deletions tests/units/project/test_holder.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@ func test_holder{

return ()
end

@external
func test_holder_revert_not_owner{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr
}():
alloc_locals

# prepare project instance
let (local context) = prepare()

# run scenario
%{ stop=start_prank(context.signers.anyone) %}

let ss = 'Holder'
let (str) = StringCodec.ss_to_string(ss)

%{ expect_revert("TRANSACTION_FAILED", "Ownable: caller is not the owner") %}
CarbonableProject.set_holder(holder_len=str.len, holder=str.data)

%{ stop() %}

return ()
end
23 changes: 23 additions & 0 deletions tests/units/project/test_image_url.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@ func test_image_url{

return ()
end

@external
func test_image_url_revert_not_owner{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr
}():
alloc_locals

# prepare project instance
let (local context) = prepare()

# run scenario
%{ stop=start_prank(context.signers.anyone) %}

let ss = 'https://image.com'
let (str) = StringCodec.ss_to_string(ss)

%{ expect_revert("TRANSACTION_FAILED", "Ownable: caller is not the owner") %}
CarbonableProject.set_image_url(image_url_len=str.len, image_url=str.data)

%{ stop() %}

return ()
end
23 changes: 23 additions & 0 deletions tests/units/project/test_land.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@ func test_land{

return ()
end

@external
func test_land_revert_not_owner{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr
}():
alloc_locals

# prepare project instance
let (local context) = prepare()

# run scenario
%{ stop=start_prank(context.signers.anyone) %}

let ss = 'Land'
let (str) = StringCodec.ss_to_string(ss)

%{ expect_revert("TRANSACTION_FAILED", "Ownable: caller is not the owner") %}
CarbonableProject.set_land(land_len=str.len, land=str.data)

%{ stop() %}

return ()
end
Loading

0 comments on commit c7d7f43

Please sign in to comment.