Skip to content

Commit

Permalink
fix: ignored loop range bounds (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgar2017 authored Jul 30, 2024
1 parent fe7d0e8 commit c41ad00
Show file tree
Hide file tree
Showing 6 changed files with 418 additions and 0 deletions.
94 changes: 94 additions & 0 deletions vyper/simple/loop/bounds/complex-0.3.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#! { "modes": [ "V <=0.3.10" ], "cases": [ {
#! "name": "default",
#! "inputs": [
#! {
#! "method": "#deployer",
#! "calldata": [
#! "0xdeadbeef01000000000000000000000000000000"
#! ],
#! "expected": [
#! "Test.address"
#! ]
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "1"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "2"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "3"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "4"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "claim_fees",
#! "caller": "0xdeadbeef42000000000000000000000000000000",
#! "calldata": [
#! "0"
#! ],
#! "expected": [
#! "1"
#! ]
#! },
#! {
#! "method": "claim_fees",
#! "caller": "0xdeadbeef01000000000000000000000000000000",
#! "calldata": [
#! "0"
#! ],
#! "expected": [
#! "4"
#! ]
#! }
#! ],
#! "expected": [
#! "100"
#! ]
#! } ] }

fees: uint256[10]
admin: address

@external
def __init__(admin: address):
self.admin = admin

@external
def claim_fees(x: uint256) -> uint256:
sum: uint256 = 0
if msg.sender != self.admin:
# Users can only call this function with x < 2 and claim the sum of 0 and 1.
for i in range(0, 2):
sum += self.fees[i]
else:
# Admin can claim everything.
for i in range(0, 10):
sum += self.fees[i]
return sum

@external
@payable
def add_fees(slot: uint256):
self.fees[slot] = msg.value
94 changes: 94 additions & 0 deletions vyper/simple/loop/bounds/complex.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#! { "modes": [ "V >=0.4.0" ], "cases": [ {
#! "name": "default",
#! "inputs": [
#! {
#! "method": "#deployer",
#! "calldata": [
#! "0xdeadbeef01000000000000000000000000000000"
#! ],
#! "expected": [
#! "Test.address"
#! ]
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "1"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "2"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "3"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "4"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "claim_fees",
#! "caller": "0xdeadbeef42000000000000000000000000000000",
#! "calldata": [
#! "0"
#! ],
#! "expected": [
#! "1"
#! ]
#! },
#! {
#! "method": "claim_fees",
#! "caller": "0xdeadbeef01000000000000000000000000000000",
#! "calldata": [
#! "0"
#! ],
#! "expected": [
#! "4"
#! ]
#! }
#! ],
#! "expected": [
#! "100"
#! ]
#! } ] }

fees: uint256[10]
admin: address

@deploy
def __init__(admin: address):
self.admin = admin

@external
def claim_fees(x: uint256) -> uint256:
sum: uint256 = 0
if msg.sender != self.admin:
# Users can only call this function with x < 2 and claim the sum of 0 and 1.
for i: uint256 in range(0, 2):
sum += self.fees[i]
else:
# Admin can claim everything.
for i: uint256 in range(0, 10):
sum += self.fees[i]
return sum

@external
@payable
def add_fees(slot: uint256):
self.fees[slot] = msg.value
94 changes: 94 additions & 0 deletions vyper/simple/loop/bounds/complex_explicit-0.3.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#! { "modes": [ "V 0.3.10" ], "cases": [ {
#! "name": "default",
#! "inputs": [
#! {
#! "method": "#deployer",
#! "calldata": [
#! "0xdeadbeef01000000000000000000000000000000"
#! ],
#! "expected": [
#! "Test.address"
#! ]
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "1"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "2"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "3"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "4"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "claim_fees",
#! "caller": "0xdeadbeef42000000000000000000000000000000",
#! "calldata": [
#! "10"
#! ],
#! "expected": [
#! "1"
#! ]
#! },
#! {
#! "method": "claim_fees",
#! "caller": "0xdeadbeef01000000000000000000000000000000",
#! "calldata": [
#! "10"
#! ],
#! "expected": [
#! "4"
#! ]
#! }
#! ],
#! "expected": [
#! "100"
#! ]
#! } ] }

fees: uint256[10]
admin: address

@external
def __init__(admin: address):
self.admin = admin

@external
def claim_fees(x: uint256) -> uint256:
sum: uint256 = 0
if msg.sender != self.admin:
# Users can only call this function with x < 2 and claim the sum of 0 and 1.
for i in range(x, bound=2):
sum += self.fees[i]
else:
# Admin can claim everything.
for i in range(x, bound=10):
sum += self.fees[i]
return sum

@external
@payable
def add_fees(slot: uint256):
self.fees[slot] = msg.value
94 changes: 94 additions & 0 deletions vyper/simple/loop/bounds/complex_explicit.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#! { "modes": [ "V >=0.4.0" ], "cases": [ {
#! "name": "default",
#! "inputs": [
#! {
#! "method": "#deployer",
#! "calldata": [
#! "0xdeadbeef01000000000000000000000000000000"
#! ],
#! "expected": [
#! "Test.address"
#! ]
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "1"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "2"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "3"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "add_fees",
#! "calldata": [
#! "4"
#! ],
#! "value": "1 wei",
#! "expected": []
#! },
#! {
#! "method": "claim_fees",
#! "caller": "0xdeadbeef42000000000000000000000000000000",
#! "calldata": [
#! "10"
#! ],
#! "expected": [
#! "1"
#! ]
#! },
#! {
#! "method": "claim_fees",
#! "caller": "0xdeadbeef01000000000000000000000000000000",
#! "calldata": [
#! "10"
#! ],
#! "expected": [
#! "4"
#! ]
#! }
#! ],
#! "expected": [
#! "100"
#! ]
#! } ] }

fees: uint256[10]
admin: address

@deploy
def __init__(admin: address):
self.admin = admin

@external
def claim_fees(x: uint256) -> uint256:
sum: uint256 = 0
if msg.sender != self.admin:
# Users can only call this function with x < 2 and claim the sum of 0 and 1.
for i: uint256 in range(x, bound=2):
sum += self.fees[i]
else:
# Admin can claim everything.
for i: uint256 in range(x, bound=10):
sum += self.fees[i]
return sum

@external
@payable
def add_fees(slot: uint256):
self.fees[slot] = msg.value
Loading

0 comments on commit c41ad00

Please sign in to comment.